簡體   English   中英

使用web.config中的location標記的IIS7和永久重定向

[英]IIS7 and permanent redirects using the location tag in web.config

我需要在IIS7下運行的ASP.NET應用程序的web.config中設置一些301永久重定向。

<configuration>
  <location path="services.htm">
    <system.webServer>
      <httpRedirect enabled="true" destination="default.aspx" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
  <location path="products.htm">
    <system.webServer>
      <httpRedirect enabled="true" destination="default.aspx" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
</configuration>

我重定向到的所有頁面都將重定向到主頁-是否有一種更快和/或更容易的方法,因為我有10多個頁面需要重定向到default.aspx? 我可以為10個頁面中的每個頁面指定一個位置部分,但是希望有一個更簡潔的方法。

您可以將.htm設置為由ASP.NET庫處理(默認情況下與.aspx相同),然后在global.ascx中的Application_BeginRequest中查看請求,並在適當時重定向。

它比Web.config中的一兩個重定向要復雜得多,但是經過一定數量后,它會變得更加容易。

將頁面一頁一頁地輸入到web.config中的一種替代方法是創建一個HttpModule IIS7 +處於集成模式時,默認情況下, HttpModules將針對所有內容(包括靜態文件)運行。

要在代碼中進行重定向,請在早期事件中調用HttpResponse.RedirectPermanent(string url, bool endResponse) 為了獲得最佳性能,請設置endResponse = true。

我建議您使用IIS URL重寫模塊。

它是一個官方模塊,您可以在這里下載: http : //www.iis.net/download/urlrewrite

此模塊就像瑞士軍刀,可以滿足所有URL重定向或重寫需求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM