ASP.NET URL重写浅析
来源:互联网 发布:泰国海苔销售量数据 编辑:程序博客网 时间:2024/05/17 09:24
详细参见: http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx
最简单的实现,就是在 Global.asax.cs 中 Application_BeginRequest 或者是 Application_AuthenticateRequest 事件处理中,对请求的URL进行判断并进行重写:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpApplication app = (HttpApplication) sender;
string requestedPath = app.Request.Path;
string lookFor = @"^/webapptest/urlrewritetest/department/(/w+)/.aspx$";
string sendTo = "/webapptest/urlrewritetest/webform2.aspx?dept=$1";
Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);
if (re.IsMatch(requestedPath))
{
string sendToUrl = re.Replace(requestedPath, sendTo);
app.Context.RewritePath(sendToUrl);
}
}
重写主要利用了 HttpContext.RewritePath 方法。
执行效果是将:
http://localhost/WebAppTest/URLRewriteTest/department/Finance.aspx
重写为:
http://localhost/WebAppTest/URLRewriteTest/WebForm2.aspx?Dept=Marketing
- ASP.NET URL重写浅析
- ASP.NET URL重写
- ASP.NET URL重写
- URL 重写(Asp.Net)
- asp.net url重写
- asp.net url重写
- url重写 asp.net
- asp.net url重写
- ASP.NET重写URL
- asp.net url重写
- asp.net url重写
- asp.net url 重写
- asp.net URL重写
- ASP.NET URL重写
- ASP.NET URL重写
- asp.net重写URL
- asp.net Url重写
- asp.net url重写
- 不同的asp.net web应用程序间共享Session/Application
- VS2005各版本比较(Express Products、Standard Edition、Professional Edition、Tools For Office、Team System)
- UNIX网络编程
- 一位编辑人员给作者们的市场汇报——冰冰子组织的市场宣传活动介绍之交互设计篇
- 坐标及其转换
- ASP.NET URL重写浅析
- 新的Blog地址
- Ajax学习资源大全
- VC 按钮添加图标,位图:
- 二进制流分步写入数据库实现(SPS中实现)
- Script Support (JDK1.6+)
- 中国最有气势的诗句!
- 盼
- IBM用户组12月最新活动现场照片