I don't understand why login page shows first when I try to view my web application

Donald Symmons 2,856 Reputation points
2023-04-23T20:56:59.17+00:00

After I publishing my first web app to test what I had been learning, I discovered that when I type the Web address in the browser address bar, it takes me to login page instead of the Default page. Why did it not show me the Default page first, is what I don't understand ? Could it be that the authentication was not properly set? But I set the Default page and some other pages like about and sign up pages as anonymous access, allowing any user to have access to the pages, but yet it still takes me to Login page; the default page doesn't show first Here is my web config

<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>

I also made some routing in the Global asax file

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");
    }

Please, what can I do to make the default page display first, as the start page when I type the web address? e.g. www.mytestwebsite.com. I just want that when I type the address like the example I show above, it takes me to the Default page instead of the Login page.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,395 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,270 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
766 questions
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 26,136 Reputation points
    2023-04-24T14:06:55.7766667+00:00

    Create a folder named "Public". Add a Default.aspx page to the Public folder. Allow all access to the Public folder in the web.config.

      <location path="Public">
        <system.web>
          <authorization>
            <allow users="*" />
          </authorization>
        </system.web>
      </location>
    

    Update the Global.asax to check if the current requested URL is the application root and the request is unauthorized. If so, redirect to ~/Public/Defualt.aspx"

    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("~/public/default.aspx");
        }
    }
    

3 additional answers

Sort by: Most helpful
  1. SurferOnWww 1,911 Reputation points
    2023-04-24T03:29:26.6533333+00:00

    Please delete <deny users="?" /> in web.config and try again. "?" means all anonymous users.

    0 comments No comments

  2. Lan Huang-MSFT 25,711 Reputation points Microsoft Vendor
    2023-04-24T08:54:41.65+00:00

    Hi @Donald Symmons,

    You try to change defaultUrl="overview.aspx" to defaultUrl="Default.aspx".

    FormsAuthentication.DefaultUrl Property:Gets the URL that the FormsAuthentication class will redirect to if no redirect URL is specified.

    If it still doesn't work, try setting <defaultDocument>.

    https://learn.microsoft.com/en-us/iis/configuration/system.webserver/defaultdocument/

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

    Best regards,
    Lan Huang


    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.


  3. AgaveJoe 26,136 Reputation points
    2023-04-24T13:15:16.4233333+00:00

    In Web Forms I place all the secured pages into a folder named "private" and add authorization to the private folder. Then you can has whatever public pages you like including the application root.