Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. changing the directory of the default.aspx page

changing the directory of the default.aspx page

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-netlearning
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jarowbear
    wrote on last edited by
    #1

    I am a beginner with asp.net and am creating a login page. If the login is correct I want the default.aspx page to be displayed. By default, it appears that asp.net looks for the default page within the main root, but I want to redirect it to look for the default.aspx page within a specific folder within the main root. How do I do that? Many thanks

    M 1 Reply Last reply
    0
    • J jarowbear

      I am a beginner with asp.net and am creating a login page. If the login is correct I want the default.aspx page to be displayed. By default, it appears that asp.net looks for the default page within the main root, but I want to redirect it to look for the default.aspx page within a specific folder within the main root. How do I do that? Many thanks

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      You can easily set the default document for your web application. Open the IIS snap-in, right click on the virtual folder containing your web application and choose Properties to open the Properties dialog. On the Documents tab, under Enable Default Document, you will see the list of default pages. Now click Add to add your default.aspx at a specific derectory, say MyDirectory, what you add is something like "MyDirectory/Default.aspx", remember to move this item to the top of the list.

      J 2 Replies Last reply
      0
      • M minhpc_bk

        You can easily set the default document for your web application. Open the IIS snap-in, right click on the virtual folder containing your web application and choose Properties to open the Properties dialog. On the Documents tab, under Enable Default Document, you will see the list of default pages. Now click Add to add your default.aspx at a specific derectory, say MyDirectory, what you add is something like "MyDirectory/Default.aspx", remember to move this item to the top of the list.

        J Offline
        J Offline
        jarow
        wrote on last edited by
        #3

        thanks for the tip but it doesn't work. I added "admin/default.aspx" in the documents tab of the IIS site and moved it to the top. It still looks for the default.aspx file in the root directory

        M 2 Replies Last reply
        0
        • J jarow

          thanks for the tip but it doesn't work. I added "admin/default.aspx" in the documents tab of the IIS site and moved it to the top. It still looks for the default.aspx file in the root directory

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          I have no idea about what code is in your login page. You are using a login page, first of all you need to set the Forms Authentication mode properly. Here is a simple setting in the Web.config:

          <authentication mode="Forms">
          <forms name="Login" loginUrl="Login.aspx"></forms>
          </authentication>

          <authorization>
          <deny users="?" /> <!--Deny all unauthenticated users -->
          </authorization>

          The code in the Login page is something like this:

          private void btnLogin_Click(object sender, System.EventArgs e)
          {
          bool isAuthenticated = ValidateUserAccount(txtUsername.Text, txtPassword.Text);
          if(isAuthenticated)
          {
          FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, true);
          }
          }

          private bool ValidateUserAccount(string username, string password)
          {
          //TODO: Validate username & password here.

          return true;
          }

          Then it works just fine. For more information, see Forms Authentication Utilities[^]

          1 Reply Last reply
          0
          • J jarow

            thanks for the tip but it doesn't work. I added "admin/default.aspx" in the documents tab of the IIS site and moved it to the top. It still looks for the default.aspx file in the root directory

            M Offline
            M Offline
            minhpc_bk
            wrote on last edited by
            #5

            I think I know the reason why it looks for the default.aspx page at the root directory. As soon as the user is validated, when you call the FormsAuthentication.RedirectFromLoginPage method, the return URL is populated based on the ReturnUrl key in the query string. If the key does not exist, the method redirects to the default.aspx that is combined from Request.ApplicationPath and the "default.aspx" string. So in this case, you might need to explicitly redirect to your default page at a specific directory in code, give the Response.Redirect method a try.

            1 Reply Last reply
            0
            • M minhpc_bk

              You can easily set the default document for your web application. Open the IIS snap-in, right click on the virtual folder containing your web application and choose Properties to open the Properties dialog. On the Documents tab, under Enable Default Document, you will see the list of default pages. Now click Add to add your default.aspx at a specific derectory, say MyDirectory, what you add is something like "MyDirectory/Default.aspx", remember to move this item to the top of the list.

              J Offline
              J Offline
              jarow
              wrote on last edited by
              #6

              thanks for you reply. The only way this works is if I change "FormsAuthentication.RedirectFromLoginPage(UserName.Text, false)" to Response.Redirect("default.aspx") don't understand why

              M 2 Replies Last reply
              0
              • J jarow

                thanks for you reply. The only way this works is if I change "FormsAuthentication.RedirectFromLoginPage(UserName.Text, false)" to Response.Redirect("default.aspx") don't understand why

                M Offline
                M Offline
                minhpc_bk
                wrote on last edited by
                #7

                I mean you can use the Response.Redirect method to explicitly redirect to the default page instead of letting the ASP.NET engine do that with the FormsAuthentication.RedirectFromLoginPage method. For example, your login page is at the root directory, and if you place your default page at "admin/default.aspx", you can use the Response.Redirect("admin/default.aspx") code to redirect to as soon as the user is validated. If your default page is at "superuser/default.aspx", your code is something like Response.Redirect("superuser/default.aspx"). In addition, to understand how the FormsAuthentication.RedirectFromLoginPage works you can try with two simple cases below: (say your web application is named as WebApplication1) + You access your login page with a short URL: http://localhost/WebApplication1/ + You access your login page with a full URL: http://localhost/WebApplication1/Login.aspx In the first case, the ASP.NET will redirect to the page that is populated based on the ReturnURL key in the query string. You can see the query string in your web browser or running the applicatio in debug mode and watch the Request instance. In the second example, the ASP.NET will redirect to http://localhost/WebApplication1/default.aspx. The reason is that the ReturnURL does not exist in the query string, so the ASP.NET engine combines the Request.ApplicationPath (the virtual application root path) with the "default.aspx" string, then redirects to this page.

                1 Reply Last reply
                0
                • J jarow

                  thanks for you reply. The only way this works is if I change "FormsAuthentication.RedirectFromLoginPage(UserName.Text, false)" to Response.Redirect("default.aspx") don't understand why

                  M Offline
                  M Offline
                  minhpc_bk
                  wrote on last edited by
                  #8

                  There is one thing that you also need to take into account is that the users of your application may want the app to redirect to their original requested file instead of the default page after the authentication validation. So in my opinion, you should first check the ReturnUrl key in the query string, if this key exists, you can call the FormsAuthentication.RedirectFromLoginPage method, otherwise go to your default page, ex. Response.Redirect("admin/default.aspx"). The sample code is something like this:

                  if(Request.QueryString["ReturnUrl"]!=null && Request.QueryString["ReturnUrl"].Length>0)
                  FormsAuthentication.RedirectFromLoginPage(UserName.Text, false);
                  else
                  Response.Redirect("admin/default.aspx");

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups