Asp.net

使用 Response.Redirect() 到相對路徑

  • December 15, 2021

我正在使用 ASP.net。我的網站託管在testIIS 根目錄下的子文件夾中。所以 default.aspx 的 url 是http://localhost/test/Default.aspx. 從 default.aspx,我想使用Reponse.Redirect()相對路徑重定向到同一網站內的另一個 url http://localhost/test/whatever,.

我試過了

Response.Redirect("/whatever");

Response.Redirect("~/whatever");

他們都重定向到http://localhost/whatever. 請注意,該Redirect方法使用 http://localhost而不是http://localhost/test/作為基本 url。

有任何想法嗎?

謝謝。

嘗試:

Response.Redirect("hello");

Response.Redirect("./hello");

享受!

抱歉,如果我過度簡化或誤解了您的問題,但您是否嘗試過:

Response.Redirect("hello");

引用自:https://stackoverflow.com/questions/2960702