Having to login twice to asp.net application due to "Default Document" in IIS

5.7k views Asked by At

Previously, I had added login.aspx to the Default Document section in IIS.

However, when someone was accessing the application, it was required to login twice. The first one wouldn't say any error message or no redirection to the next page in the application. And the second one would actually redirect the user to the expected page. And the user was using the right credentials both times.

As soon as I deleted login.aspx from the Default Document section in the IIS, and the user provided the full link to the application (~/login.aspx), the problem was gone as it was only required to login once.

Does anyone know why this is happening?

3

There are 3 answers

0
aleafonso On BEST ANSWER

In order to solve this problem, in the Page_Load event of the Default Document, it must be checked the following:

if (this.User.Identity.IsAuthenticated)
{
    Response.Redirect("somepage.aspx");
}

Source: asp.net Form Authentication change .net 2 to .net4

5
Germann Arlington On

Do you have have index page set as default and present?

From your scarce information I can find one (of possible many) explanation:

first you get to yoursite.com (without specifying the login.aspx) it redirects to login.aspx behind the scenes but url stays the same. When you submit from login.aspx it probably goes to some other (existing) page, which redirects the user to login.aspx (rewriting the url this time).

IF you want better explanation you will need to provide more details

0
Kemboi On

In Global.asax add these lines

void Application_BeginRequest(object sender, EventArgs e)
{
    if (Request.QueryString.ToString().EndsWith("ReturnUrl=%2f"))
              System.Web.HttpContext.Current.Response.Redirect("~/login.aspx");

    if (Request.AppRelativeCurrentExecutionFilePath == "~/")
        HttpContext.Current.RewritePath("login.aspx");//This is the default page to navigate after a successful login.

}