是否可以配置服务器以允许使用和不使用.aspx扩展的链接。
如果是,我该如何设置呢。
我正在使用umbraco的客户端网站上工作。我知道它内置了友好的URL功能。不幸的是,该网站已经存在,并且为所有链接启用了该功能。
问题是他们想要使用像www.sitename.com/promotion这样的促销网址,而不必附加.aspx扩展名。而且我们不希望在网站上重新启用网址并且必须跟踪所有损坏的链接时遇到麻烦。
答案 0 :(得分:3)
Scott Guthrie在此发表了一篇好文章。
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
答案 1 :(得分:1)
我之前通过编写一个简单的HttpModule来做到这一点,需要注意几点:
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. } }
答案 2 :(得分:0)
在完全控制URI 部分的下半部分提供了链接和许多实现此目的的方法: http://blogs.msdn.com/bags/archive/2008/08/22/rest-in-wcf-part-ix-controlling-the-uri.aspx