Phil Sando

  Home  |   Contact  |   Syndication    |   Login
  13 Posts | 0 Stories | 3 Comments | 0 Trackbacks

News

Twitter












Archives

Image Galleries

Here is my web.config used to login protect a folder called administration;

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <customErrors mode="Off">
    </customErrors>
    <authentication mode="Forms">
      <forms name=".ASPXAUTH" loginUrl="login.aspx" protection="All" timeout="999999">
        <credentials passwordFormat="MD5">
          <user name="admin" password="21232F297A57A5A743894A0E4A801FC3" />
        </credentials>
      </forms>
    </authentication>
    <authorization>
      <allow users="?" />
      <allow users="*" />
    </authorization>
    <trace enabled="true" localOnly="false" />
  </system.web>
  <location path="administration">
    <system.web>
      <authorization>
        <allow users="admin" />
        <deny users="*" />
      </authorization> 
    </system.web>
  </location>
</configuration>

I'm using it in this asp.net vb web site which I built from some tutorials and added a few extra bits of functionality to.

posted on Saturday, February 27, 2010 2:52 PM

Feedback

# re: Web.config file to password protect a directory in any ASP.net web site 12/23/2010 2:13 AM Kabroo
Thanks good post, but I have a question. What would be web.config setting to protect folder by using IP address? I don't want let users to type passwords, the rule should be simple if user IP == "bla" then user can see the page else redirect to someother page.

# re: Web.config file to password protect a directory in any ASP.net web site 12/23/2010 8:05 AM Abdul Kaleem
Thanks for sharing the code.
I have a similar task of protecting the folder called 'Admin' which holds couple of files which i want to the end user to access after login. i have managed to use your code and the user is being asked for login credentials. but after logging in its redirected to the default.aspx page instead of returlUrl. Please help! I am new to ASP .Net and don't have any experience. It would be great if you could provide me sample files for the same. i am struggling with this for 10 days.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: