Search code examples
c#asp.netweb-configiis-7.5

Asp.net redirect from login to main page


i have 2 pages on my webapp. Login.aspx and Main.aspx.

After a successful login username and password i redirect from login.aspx to Main.aspx as shown below in c#. This works fine in visual studio 2010. The problem is that when i deploy my website the value localhost does not make sense.

Can i determine the server name that the website is running on or should i somehow place the server redirect main page link in my web.config file?

thanks Damo

string Redirectport = HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
RedirectURL = "http://localhost:" + Redirectport + System.Web.HttpContext.Current.Response.ApplyAppPathModifier("~/Main.aspx");

Solution

  • How about

    RedirectURL = Page.ResolveUrl("~/Main.aspx") ?

    this is the "default" way to do it.