Folder protection with webconfig

Discussion in '.NET' started by lupis, Jul 22, 2010.

  1. lupis

    lupis

    Joined:
    Jul 20, 2010
    Messages:
    1
    Hi,

    I am new to asp.net and I have subfolder in my rootfolder with files that needs to accessed by username and login from a loginpage. I have currently one default.aspx that I access this way in the root folder. This is a extract from my current webconfig file in the root folder:

    Code:
    <authentication mode="Forms">
          <forms name="appNameAuth" path="/" loginUrl="login.aspx" protection="All" timeout="30">
            <credentials passwordFormat="Clear">
              <user name="Member" password="xxx"/>
              
            </credentials>
          </forms>
        </authentication>
        <authorization>
    
          <deny users="?"/>
    
        </authorization>
    But I want to move this page and have additional pages in a subfolder that are only accessed by the above mentioned credentials in my root webconfig file.

    This is the function I am using on the Login.aspx page in my root folder:

    Code:
    Sub ProcessLogin(objSender As Object, objArgs As EventArgs)
    
      If FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text) Then
         FormsAuthentication.RedirectFromLoginPage(txtUser.Text, chkPersistLogin.Checked)
      Else
         ErrorMessage.InnerHtml = <font color="red">"<b>Nåt gick fel...</b>var vänlig och kontollera användarnamn samt lösenord..."</font>
      End If
    All the pages in the subfolder will have the following code:

    Code:
    Sub Page_Load()
      'verify authentication
      If User.Identity.IsAuthenticated Then
        'display Credential information
                displayCredentials.InnerHtml = "&nbsp; You are logged in as: " & User.Identity.Name
                   
                '<br>Authentication Used : <b>" & User.Identity.AuthenticationType & "</b>"
      Else
        'Display Error Message
        displayCredentials.InnerHtml = "Sorry, you have not been authenticated."
      End If
    End Sub
    
        Protected Sub lnkLogut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkLogut.Click
            
            'delete the users auth cookie and sign out
            FormsAuthentication.SignOut()
            'redirect the user to their referring page
            Response.Redirect(Request.UrlReferrer.ToString())
        End Sub
    Every page in the root folder should be accessable by everyone, but only the pages in the subfolder should be accessed by login.

    Thanks
    Sohail
     
    lupis, Jul 22, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Omundu

    Webconfig Error

    Omundu, Jul 18, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    417
    Rajeev Soni
    Jul 19, 2003
  2. Buz Waitz

    webconfig error

    Buz Waitz, Oct 30, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    427
    Jacob Yang [MSFT]
    Nov 14, 2003
  3. Jenny

    webconfig

    Jenny, Nov 12, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    501
  4. Keith Chadwick

    webConfig AppSettings file to virtual?

    Keith Chadwick, Nov 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    443
    Keith Chadwick
    Nov 25, 2003
  5. g
    Replies:
    69
    Views:
    2,201
    Oliver Wong
    Apr 25, 2006
Loading...

Share This Page