2011-09-26 90 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