简体   繁体   中英

asp.net basic authentication

I have an intranet site with basic authentication.

Is it possible to have just one page not ask for the credetials? As in allow access to anyone just for the one page?

Can something be set in web.config for the single page?

Add the following element to the configuration node you web.config:

<location path="aFolder/aPageToExclude.aspx">
     <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>

For more info and usage have a look at the MSDN documentation: Location Element (ASP.NET Settings Schema)

What I do is that I don't use ASP.Net Authentication. What I do is when the user enters their username and password, I check the database for if a row with that username and password exists.

You can do that using objDataSet.Tables[0].Rows.Count > 0 . You can put that in an 'if' condition and then take the username and put it in a session. You do this like this:

Session["username"] = (Username Variable Here) . Then, you create two master pages, one is for pages that are only accessible to a logged in person, and one that is accessible for anyone. In the master page that only gives access to a person who is logged in, you can check if the session data is null or not. If it is null, you can redirect that person back to the login page. The LoggedIn master page can just stay as is. If you already have a master page, then you can duplicate it, and add that condition. If you have not implemented master pages yet, you can put the condition in the page load of every page that needs a user to be logged in to access that page. Because you are using sessions and not cookies, it will be harder for a user to hack into this system.

you need to overwrite your web.config file settings.
you need to create one folder and create one more web.config file in that folder.
Then put Page.aspx in that folder.
Then modify that web.config file code like below:

<authentication mode="Forms">
</authentication>

Note:

1) you don't have to mention users=* it's automatically allows all the users to access those pages under that folder.

or

What you can do is if you are already using directory structure for pages, then you can keep that page.aspx in the same level where you have Login page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM