Share via

Login required for Default/home page, even with anonymous access

Donald Symmons 3,096 Reputation points
2023-04-21T12:15:12.3433333+00:00

There is something that crossed my mind while trying to publish and view my test web application on a live server. After publishing the web application, I tried to view the application but I redirected me to the login page. But it was supposed to take me to the Default page. Then I figured that I had done routing in the Global asax file to some pages that anonymous or every user can be able to view. Does this mean web forms authentication in the web config does not recognize routing in Global asax file? Please I want help in learning how to resolve this. Thank you

<system.web>
    <trust level="Full"/>
    <sessionState timeout="40"></sessionState>
    <authentication mode="Forms">
      <forms name="login" timeout="40" cookieless="UseCookies" loginUrl="Login.aspx" defaultUrl="overview.aspx" slidingExpiration="true" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" maxRequestLength="3145728" />
    <customErrors mode="Off" />
    <pages enableEventValidation="false">
      <controls>
        <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
      </controls>
    </pages>
  </system.web>
<location path="Signup.aspx">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
  <location path="Default.aspx">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
  <location path="About.aspx">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>


Global.asax

 void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
                ScriptManager.ScriptResourceMapping.AddDefinition("jquery", 
    new ScriptResourceDefinition
{
Path = "~/scripts/jquery-1.7.2.min.js",
DebugPath = "~/scripts/jquery-1.7.2.min.js",
CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.min.js",
CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.js"
});

         RegisterRoutes(RouteTable.Routes);
    }
 static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("About", "about", "~/About.aspx");
        routes.MapPageRoute("Login", "login", "~/Login.aspx");
        routes.MapPageRoute("Signup", "signup", "~/Signup.aspx");
    }
Developer technologies | .NET | Other
Developer technologies | ASP.NET Core | Other

Answer accepted by question author

QiYou-MSFT 4,341 Reputation points Microsoft External Staff
2023-04-24T09:47:00.88+00:00

Hi @Donald Symmons

You can try adding the following code to web.config:

<configuration>
   <system.webServer>
      <defaultDocument enabled="true">
         <files>
            <add value="Default.aspx" />
         </files>
      </defaultDocument>
   </system.webServer>
</configuration>

This is the relevant introductory document:

Document

At the same time, on the anonymous authentication settings of IIS, I think the following documentation will also help you:

Document

Best Regards,

Qi You


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Donald Symmons 3,096 Reputation points
    2023-04-25T06:14:41.61+00:00

    Hi @QiYou-MSFT , I tried that and it did not work. But I was taught another way. This is the code that was put in the Global.asax file, and upon typing the web address and clicking the "enter" button, it redirects to the default page

    protected void Application_AuthenticateRequest(Object sender, EventArgs e)
    {
        string domainName = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/";
        if (!Request.IsAuthenticated & Request.Url.ToString() == domainName)
        {
            Response.Redirect("~/default.aspx");
        }
    }
    

    Was this answer helpful?

    0 comments No comments

  2. Bruce (SqlWork.com) 84,071 Reputation points
    2023-04-21T15:19:17.98+00:00

    you are correct, webform authentication via web.config only looks at the request url, and has no knowledge of routing. You will need to add a route paths.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.