Url rewriting Gloabl.asax Context.RewritePath IIS 7.5
以下代码段在调试模式下运行时运行良好,但在通过IIS(7.5)运行时抛出404 是否需要为IIS添加web.config设置Url rewriting Gloabl.asax Context.RewritePath IIS 7.5,url-rewriting,global-asax,Url Rewriting,Global Asax,以下代码段在调试模式下运行时运行良好,但在通过IIS(7.5)运行时抛出404 是否需要为IIS添加web.config设置 protected void Application_BeginRequest(object sender, EventArgs e) { string currentUrl = Request.Url.ToString(); List<string> pages = new List<string>();
protected void Application_BeginRequest(object sender, EventArgs e)
{
string currentUrl = Request.Url.ToString();
List<string> pages = new List<string>();
pages.Add("/about-us.html");
pages.Add("/services");
foreach (string page in pages )
{
if (currentUrl.Contains(page))
{
Context.RewritePath(string.Format("/page.aspx?page={0}", page));
}
}
}
受保护的无效应用程序\u BeginRequest(对象发送方,事件参数e)
{
字符串currentUrl=Request.Url.ToString();
列表页=新列表();
pages.Add(“/about us.html”);
第页。添加(“/服务”);
foreach(页面中的字符串页面)
{
if(currentUrl.Contains(第页))
{
重写路径(string.Format(“/page.aspx?page={0}”,page));
}
}
}
您需要在Web.config的
中添加
。谢谢,效果很好。对于简单的站点,我认为Context.RewritePath的概念是可以的,您什么时候会推荐system.web.routing而不是这个方法?我的web.config文件中已经有了这个,但是IIS 7.5和Context.RewritePath仍然存在问题。还有其他建议吗?你有没有理由尝试自己做这件事,而不是使用内置的IIS 7.5支持或类似托管融合Url重写器的东西?