2010-06-02 87 views
10

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

我試圖

Response.Redirect("/whatever"); 

Response.Redirect("~/whatever"); 

他們都重定向到http://localhost/whatever。請注意,Redirect方法使用http://localhost而不是http://localhost/test/作爲基礎URL。

任何想法?

謝謝。

+0

我自己犯了一個愚蠢的錯誤。的Response.Redirect( 「〜/不管」);應該去http:// localhost/test/whatever。謝謝你們 。 – Shuo 2010-06-02 20:02:22

回答

12

嘗試:

Response.Redirect("hello"); 

Response.Redirect("./hello"); 

享受!

2

很抱歉,如果我是過度簡化或誤解你的問題,但你只是嘗試:

Response.Redirect("hello"); 
0

試試這個(我的例子是VB.net)

Dim url As String = "~/SomeDirectory/SomePage.aspx" 
    Response.Redirect(url.Replace("~"c, Request.ApplicationPath)) 

我喜歡在一個類中有Utils.RedirectRelative( 「〜/ SomeDirectory/SomePage.aspx頁面」)的地方,但我不知道如何「好習慣」就是這樣。