[英]Response.Redirect on Page with Url Rewritten by IIS Url Rewrite Module
我正在使用IIS Url Rewrite模塊重寫我的ASP.Net Web應用程序的URL。 Urls正在改寫自:
http://domain/version/page.aspx
至
http://domain/company/page.aspx
當使用絕對路徑直接瀏覽時,它可以正常工作。 使用相對路徑在應用程序中導航時會出現問題。 任何一種相對路徑。
所有相對路徑都重定向到相應的http://domain/version/page.aspx
而不是它應該去的http://domain/COMPANY/page.aspx
。
我通過將此行添加到Global.asax中的BeginRequest事件來解決了很多問題:
Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)
HttpContext.Current.RewritePath(HttpContext.Current.Request.Url.AbsolutePath, True)
End Sub
本質上,它只是將虛擬路徑重新定位到請求的URL。
但即使使用Response.Redirect STILL重定向到實際路徑而不是虛擬路徑。
所以這段代碼: Response.Redirect("~/test.aspx")
將重定向到domain/Version/test.aspx
而不是domain/Company/test.aspx
如何使Response.Redirect重定向到虛擬路徑( domain/COMPANY/test.aspx
)而不是實際路徑( domain/VERSION/test.aspx
)
謝謝。
兩種選擇。 你可以這樣做:
Response.Redirect("/company/test.aspx")
要么
Response.Redirect("http://domain/company/test.aspx")
這是使用動態URLS的挑戰之一,如果要使用動態URL,則需要處理。
可能最好的解決方案是編寫一個所有頁面都可以看到的功能。 這樣你就可以寫:
MyRedirectFunction("test.aspx")
所有細節都在幕后。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.