Monday, May 27, 2013

ReturnUrl=%2f Issue in ASP.NET Forms Authentication

Some time back I used FormsAuthentication in an ASP.NET  project and everything seemed to be working fine expect for a one issue.

When I Loged into the application and clicked on LogOut it was navigating to the LogIn page and it adds 'ReturnUrl=%2f' to the Return URL and it caused me to click on the LogIn button twice with correct authentication details, in order to navigate to the default page. I added the below code snippet and it solved the issue for me.

In Global.asax.cs file.

    void Application_BeginRequest(object sender, EventArgs e)
        if (Request.AppRelativeCurrentExecutionFilePath == "~/")
            HttpContext.Current.RewritePath("~/Gate/Index.aspx");//This is the default page to navigate after a successful login.

Write comments
Recommended Posts × +