Olga
Olga

Reputation: 11

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\Website2 - /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.

Upvotes: 1

Views: 914

Answers (3)

Zhaph - Ben Duguid
Zhaph - Ben Duguid

Reputation: 26966

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.

Upvotes: 1

Edgar Hernandez
Edgar Hernandez

Reputation: 4030

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

Upvotes: 1

Josh Pearce
Josh Pearce

Reputation: 3455

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.

Upvotes: 0

Related Questions