2011-09-26 68 views
0

我是新來的asp.net和c#。我設置了一個查詢字符串,將值傳遞給另一個頁面以及url路徑。但一旦轉到此頁面,我將無法重定向到任何其他頁面。走出URL.Authority?

這裏是我的代碼:

Uri url = System.Web.HttpContext.Current.Request.Url; 
string urlString = "http://" + url.Authority + "/Projects/SearchResult.aspx/?Keywords=" + TxtSearch.Text; 
Response.Redirect(urlString); 

以下是錯誤:

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Projects/Description.aspx/NewPost.aspx

+1

爲什麼downvote? –

回答

1

的誤差只是表明錯你的URL - 報告的網址/Projects/Description.aspx/NewPost.aspx反正似乎是錯的 - 它應該是/Projects/Description.aspx/Projects/NewPost.aspx。當您的代碼重定向到完全不同的頁面(/Projects/SearchResult.aspx)時,您應該檢查該頁面代碼以進行上述重定向/傳輸。

在側面說明,有幾個在浩你正在形成的URL的問題:

  1. 查詢字符串不正確傳遞 - 您使用尾隨問號之前的斜線即/?Keywords - 你應該使用/Projects/SearchResult.aspx?Keywords=
  2. 通常情況下,傳遞到應用程序中的URL,你應該使用~作爲應用程序根 - 這樣,你不用擔心主機名&根虛擬目錄(如果有的話)。例如,您可以編寫

    Response.Redirect(「〜/ Projects/SearchResult.aspx?Keywords =」+ TxtSearch.Text);

+0

尊敬的Vinay C,感謝您對我的回答,我可以重定向到我的頁面併成功解決問題 – Jpaul