时间:2016-02-15 22:29 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【Global.asax的Application_BeginRequest实现url重写无后缀的代码】,下面是详细的讲解!
Global.asax的Application_BeginRequest实现url重写无后缀的代码
<%@ Application Language="C#" %>
<script RunAt="server">
void Application_BeginRequest(object sender, EventArgs e)
{
string oldUrl=System.Web.HttpContext.Current.Request.RawUrl; //获取初始url
//~/123.aspx → ~/Index.aspx?id=123
Regex reg=new Regex(@"^\/\d+\.html");
if (reg.IsMatch(oldUrl))
{
string id=reg.Match(oldUrl).ToString().Substring(1, reg.Match(oldUrl).ToString().LastIndexOf(".") - 1);
Context.RewritePath("~/Index.aspx?id=" + id);
}
//~/123 → ~/Index.aspx?id=123
Regex reg1=new Regex(@"^\/\d+$");
if (reg1.IsMatch(oldUrl))
{
string id=reg1.Match(oldUrl).ToString().Substring(1);
Context.RewritePath("~/Index.aspx?id=" + id);
}
//~/index/123 → ~/Index.aspx?id=123
Regex reg3=new Regex(@"^\/index\/\d+$");
if (reg3.IsMatch(oldUrl))
{
string id=reg3.Match(oldUrl).ToString().Substring(7);
Context.RewritePath("~/Index.aspx?id=" + id);
}
}
</script>
关于Global.asax的Application_BeginRequest实现url重写无后缀的代码的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【asp】asp.net ubb使用代码-net-ubb使用
- 【默认图片】图片不存在使用默认图片代替的实例
- 【asp】asp.net 页面转向 Response.Redirect Ser
- 【页面打印】关于ASP.NET页面打印技术的常用方法
- 【MVC5】MVC 5 第一章 创建MVC 5 web应用程序-net
- 【MVC】一个简单MVC5 + EF6示例分享-EF6实例-MVC5
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
