2008-09-28 62 views
1

可以將服務器配置爲允許使用帶和不帶.aspx擴展名的鏈接。具有和不具有.aspx擴展名的鏈接

如果是的話,我該怎麼去設置它。

我正在使用umbraco的客戶端網站上工作。我知道它建立在友好的URL可信度。不幸的是,該網站已經開始生效,併爲整個鏈接開啓了功能。

問題是他們想使用www.sitename.com/promotion等促銷網址,而不必附加.aspx擴展名。我們不想經歷網址重寫網站廣泛的問題,並且必須追蹤所有斷開的鏈接。

+0

你究竟想要完成什麼? – 2008-09-28 20:18:12

回答

1

我做這個之前,通過編寫一個簡單的HTTP模塊,有幾件事要注意:

  • 您需要將IIS中的404錯誤指向aspx頁面,否則IIS將不會調用ASP.NET runtim e和HTTPModule永遠不會命中。
  • 這最適合從虛榮網址中抓取並重定向,而不是作爲全功能的urlrewrite。
 
    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. 
     } 
    } 
相關問題