C# 带和不带.aspx扩展名的链接

C# 带和不带.aspx扩展名的链接,c#,asp.net,vb.net,url-rewriting,iis-6,C#,Asp.net,Vb.net,Url Rewriting,Iis 6,可以将服务器配置为允许在使用和不使用.aspx扩展名的情况下使用链接 如果是的话,我该如何着手进行设置 我在使用umbraco的客户网站上工作。我知道它内置了友好的URL功能。不幸的是,该网站已经上线,并为大量链接启用了该功能 问题是他们想使用推广URL,如www.sitename.com/promotion,而不必附加.aspx扩展名。我们不想经历在站点范围内启用url重写和跟踪所有断开链接的麻烦。Scott Guthrie对此有一篇很好的帖子 Scott Guthrie在这方面有一个很好的帖

可以将服务器配置为允许在使用和不使用.aspx扩展名的情况下使用链接

如果是的话,我该如何着手进行设置

我在使用umbraco的客户网站上工作。我知道它内置了友好的URL功能。不幸的是,该网站已经上线,并为大量链接启用了该功能


问题是他们想使用推广URL,如www.sitename.com/promotion,而不必附加.aspx扩展名。我们不想经历在站点范围内启用url重写和跟踪所有断开链接的麻烦。

Scott Guthrie对此有一篇很好的帖子


Scott Guthrie在这方面有一个很好的帖子


在“完全控制URI”一节的下半部分,提供了链接和许多实现此目的的方法:

在“完全控制URI”一节的下半部分提供了链接和实现此目的的多种方法:

我以前写过一个简单的HttpModule,需要注意以下几点:

您需要将IIS中的404错误指向aspx页面,否则IIS将不会调用ASP.NET运行时,HTTPModule将永远不会命中。 这最适合从虚荣URL捕获和重定向,而不是作为一个功能齐全的URL重写。
我以前写过一个简单的HttpModule,需要注意以下几点:

您需要将IIS中的404错误指向aspx页面,否则IIS将不会调用ASP.NET运行时,HTTPModule将永远不会命中。 这最适合从虚荣URL捕获和重定向,而不是作为一个功能齐全的URL重写。
你到底想完成什么?我在编辑中回答了你的问题。你到底想完成什么?我在编辑中回答了你的问题。 public class UrlRewrite : IHttpModule { public void Init(HttpApplication application) { application.BeginRequest += (new EventHandler(this.Application_BeginRequest)); } private void Application_BeginRequest(Object source, EventArgs e) { // The RawUrl will look like: // http://domain.com/404.aspx;http://domain.com/Posts/SomePost/ if (HttpContext.Current.Request.RawUrl.Contains(";") && HttpContext.Current.Request.RawUrl.Contains("404.aspx")) { // This places the originally entered URL into url[1] string[] url = HttpContext.Current.Request.RawUrl.ToString().Split(';'); // Now parse the URL and redirect to where you want to go, // you can use a XML file to store mappings between short urls and real ourls. string newUrl = parseYourUrl(url[1]); Response.Redirect(newUrl); } // If we get here, then the actual contents of 404.aspx will get loaded. } public void Dispose() { // Needed for implementing the interface IHttpModule. } }