开发者

Redirection between two websites within one solution (ASP.NET + VS 2008 + IIS 5.1)

I have an issue with redirecting from one asp website to another within one VS solution. I have set up virtual directories as follows: C:\WebSites\Website1 - /Website1 C:\WebSites\Websi开发者_开发问答te2 - /Website2 My starting website is Website1. I want to redirect user to Website2. I use Response.Redirect("/Website2/Default.aspx") and get 404 error. What am I doing wrong? Any advices are highly appreciated! Thank you in advance.


Lets say the current page is

   http://localhost/Website1/Default.aspx,

if you do a Redirect like this

   Response.Redirect("/Website2/Default.aspx")

in there, the URL you are redirecting is

    http://localhost/Website1/WebSite2/Default.aspx

which don't exists.

You have to redirect to a full URL instead of a relative URL.

Something like
Response.Redirect("http://localhost/Website2/Default.aspx")

Hope it Helps


You could always pick the server name out of the HttpRequest.Url or HttpRequest.ServerVariables objects.

Response.Redirect(string.Format("http://{0}/WebSite2/default.aspx", 
                                Request.Url.Host));

Or

Response.Redirect(string.Format("http://{0}/WebSite2/default.aspx", 
                                Request.ServerVariables["HTTP_HOST"]));

Which will save you hardcoding the server name in the redirects.


When you have two virtual directories, if they are configured to be their own applications, then their individual roots are considered THE root, and you will have to redirect to a full URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜