implement form authentication on some pages not all pages - asp.net

I want to implement form authentication on some pages not all pages.
In my application many other pages are there which I want make as public like contact us, about us and all.
For some pages I want to implement form authentication.
Please help me on this.
<authorization>
<deny users ="?" />
<allow users = "*" />
</authorization>

If you had a directory called "Administration" which contained all the administration pages, you could add the following to your web.config:
<location path="Administration">
<system.web>
<authorization>
<allow roles="Admin" />
<deny users="*" />
</authorization>
</system.web>
</location>
Then only users in the role "Admin" can access the pages in the "Administration" directory. The path can also be substituted for a specific page rather than a directory if required.

You can create different directories for different pages. For example those pages that you want to make public to every one can be in one folder and put a web.config file on that folder allowing to all users.

Try Something like that
<configuration>
<location path="test.aspx">
<system.web>
<authorization>
<allow users="?"/>
<deny users="*" />
<authorization>
</system.web>
</location>
</configuration>
Check For More knowledge
Hope it works for you.

Related

How to Secure More Folders for a Website in ASP.Net

I have Created as Website in ASP.Net. In which I have More Folders like ESearch, Admin, Content, MasterFile. Each Folders containts more webpages.
I want to secure all the folders for Users who are not admin and i want all rights for ADMINISTRATOR.
I have the Web.config like this....
<location path="Admin">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
Please help me to solve this issue...
Allow only Admin role/group users like below which will make sure that only users with Admin privilege will be able to access the pages.
<authorization>
<allow roles="Administrator"/>
<deny users="*"/>
</authorization>
Read more about this in MSDN

How to give permission in web.config file for users,admin,others?

I am getting confused to give permission for user's ,admin and others in web.config.
this is my web.config
<authorization>
<deny users="*"/>
<allow users ="neerajjadon" roles ="Admin">
</authorization>
Now i login with name neerajjadon then one new page is coming on this page i have one link button to move to another page.If i am clicking on this linkbutton then its not going to next page it is going to login page again.
Please help me.
If the other page is in a sub folder then perhaps you could add in a seperate web.config in that directory with:
<authorization>
<deny users="*"/>
<allow users ="neerajjadon" roles ="Admin">
</authorization>
or another option, probably not practical but you can add authorization to specific pages like:
<location path="page 1.aspx">
<system.web>
<authorization>
<allow users ="neerajjadon" roles ="Admin">
<deny users="*"/>
</authorization>
</system.web>
</location>

Access Rules on individual pages ASP.net

I am using site map for navigation in my website. Is there any way that I could imply access rules on specific pages based on individual user, not on roles based. Each user will have its access right to each page.
I have explored access rules security, its implying on individual user but on folder based, not page based.
I don't want to create new table in database that will have each page path info.
You can use a <location> element in web.config to specify users per-page.
<configuration>
<location path="JohnsPage.aspx">
<system.web>
<authorization>
<allow users="John" />
<deny users="*" />
</authorization>
</system.web>
</location>
</configuration>
This works based from the username the user is logged in as. If you're using integrated windows authentication don't forget you might need to specify the domain too like <allow users="DOMAIN\John" />
You can confugure it in web.config as follows:
<?xml version="1.0"?>
<configuration>
<location path="AnyUserPage.aspx">
<system.web>
<authorization>
<allow users="AnyUser" />
<deny users="*" />
</authorization>
</system.web>
</location>
</configuration>

How to allow anonymous user to browse the Style folder

In my web application I want the anonymous user to browse only the login page, and It's OK now but it appears without style!
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
</system.web>
<location path="Style">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
Any help!
From this article:
Images and CSS files
Say you have all your images and CSS in a seperate folder called images and you are denying anonymous access to your website. In that case you might see that on your login page you cannot see images(if any) and css(if any) applied to your login page controls.
In that case you can add a web.config to the images and css folder and allow access to everyone to that folder. So your web.config in images folder should look as below:
<configuration>
<system.web>
<authorization>
<allow users="*"/> //Allow everyone
</authorization>
</system.web>
</configuration>
The most popular answer of:
<configuration>
<system.web>
<authorization>
<allow users="*"/> //Allow everyone
</authorization>
</system.web>
</configuration>
..is correct.. but if this fails to work then you need to verify that the Authentication is setup as you expect and that the user under which Anonymous is configured to run has read access to all of the folders you need.
NOTE: If you have multiple web.configs you may need to check each folder with its own web.config.
Check the Web Application
Open the "IIS/Authentication" for your web application and click "edit" on the entry marked "Anonymous Authentication".
If a specific user is specified then ensure that the specified user has access to your folders.
If "Application pool identity" is set then you will need to check the application pool configuration.
Check the Application Pool
Find the Application Pool for your app and click on "Advanced Settings" and search for the item named "Identity".
If the identity is "ApplicationPoolIdentity" then the group you will need to give access to your files to "IIS_IUSRS".
For more information on "IIS_IUSRS" please see: http://learn.iis.net/page.aspx/140/understanding-built-in-user-and-group-accounts-in-iis/
use
<allow users="*" />
for styles folder, so every user can use the style.
using
<location path="admin">
<system.web>
<authorization>
<deny users="*" />
<allow users="?" />
</authorization>
</system.web>
</location>
you can allow access to Admin folder for only authenticated users.

Forms authentication Of Asp.net

I am working on Asp.net Application where I have 4 roles in my application. 1. Admin 2. User 3. Reseller 4. Affiliate. And I am Using Form Authentication for this everything was working fine for single role(User). But now i have 4 roles and I am not getting how to manage this. I have 4 folders for different Users.
If i login with reseller account and if i change the url for user then its allowing me to access user part also. But i don't want this. I need in my app that user can access only his access area. Means If your reseller logged in then he can only access reseller pages or same folder nothing else.
Please help me to find this solution.
You can use the web.config to set the permission or you can also get more granular and decorate the class or method you want to lock down like this:
[PrincipalPermissionAttribute(SecurityAction.Demand, Role = #"Administrators")]
All of this is part of the role manager that you can set up. Start by reading this article that explains what to do.
There's two things to look at here. First of all, restricting access to each folder by role ought to be straightforward enough if you use <location> elements in your web.config e.g.
<location path="Resellers">
<system.web>
<authorization>
<allow roles="Reseller"/>
<deny roles="*"/>
</authorization>
</system.web>
</location>
<location path="Users">
<system.web>
<authorization>
<allow roles="User"/>
<deny roles="*"/>
</authorization>
</system.web>
</location>
...
Also in your individual pages, you can call the IsUserInRole function to check whether your user is in the correct role to access the page.
You might want to get hold of a copy of Beginning ASP.NET Security, it's got great information on how to do this.
You need to set the appropriate authentication settings in a web.config file for each folder you are restricting access to, i.e.
<authorization>
<deny users="?" />
<allow roles="Administrators" />
<deny users="*" />
</authorization>
Will allow access only to validated users with the role of "Administrators".
In each of the folders you have to place a web.config file that restricts access to the role in question. For example, in the resellers folder you have a web.config containing:
<authorization>
<deny users="*"/>
<allow roles="Resellers"/>
</authorization>
And so on for the other folders.
use like below code:
<location path="Users">
<system.web>
<authorization>
<allow roles="Users"/>
<deny users="*"/>
</authorization>
</system.web>
</location>

Resources