To log into asp.net application twice due to “Document Default” in IIS

I previously added login.aspx to the Default File section in IIS.

However, when someone accessed the application, they had to log in twice. The first one would not say a single error message or redirect to the next page of the application. And the second one can redirect the user to the expected page. And the user used the correct credentials both times.

As soon as I delete login.aspx from the Default Document section in IIS, and the user provided a full link to the application (~ / login.aspx), the problem disappeared, since it only needed to be logged in once.

Does anyone know why this is happening?

+5
source share
3 answers

To solve this problem, in the Page_Load event of the default document, you need to check the following:

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

Source: Changing the authentication form of asp.net.net 2 in .net4

+1
source

Do you have a default index page and is present?

From your meager information, I can find one (of the possible) explanation:

first you get to yoursite.com (without login.aspx) it redirects to login.aspx backstage, but the url remains unchanged. When you submit from login.aspx, it probably goes to another (existing) page that redirects the user to login.aspx (by rewriting the URL this time).

,

0

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.

}
0
source

All Articles