ASP.NET Unable to use custom Window group as a Role - asp.net

I want to use a local group to restrict access to an ASP.NET web application to local users.
I've created a Windows group (TestLocalGroup) and Windows user accounts and assigned them all to the new group. The group and accounts are on the IIS7 web server.
In my web.config, I can properly restrict access to specific users by defining the following settings...
<authentication mode="Windows" />
<authorization>
<allow users=".\TestLocalUser1,.\TestLocalUser2" />
<deny users="*" />
</authorization>
But I can't seem to get it to work for the group. This code won't allow my group members access...
<authentication mode="Windows" />
<authorization>
<allow roles=".\TestLocalGroup" />
<deny users="*" />
</authorization>
I don't have any "roleManager" section. Do I need that?
Am I missing something? It seems like it should just work.

There were two problems.
1) It turns out that I had a different roleManager enabled on a parent web.config.
<roleManager enabled="true" defaultProvider="SqlRoleManager">...
For my site I had to clear the roleManager to get the windows roles to work again.
<roleManager enabled="false" />
2) As I was adding my users to the groups, there didn't appear to be any immediate effect. I logged on and off as suggested by mellamokb (Thank you!). That didn't make any difference, but it did point me to the correct solution; recycling my web site. I assume there is some timed credential cache and recycling the web site will clear it.

In my case,,, I have to delete roleManager... from my web.config.

Related

Anonymous on the entire site except for one page using asp.net

I would like to have anonymous access for an entire asp.net site except for one page. On that one page, I would still like everyone to access the page but I would like to retrieve their username. Here is what I have so far:
In the web.config, system.web section I am requesting windows authentication:
<authentication mode="Windows">
</authentication>
Then I am specifying the location that I would like to force windows authentication:
<location path="forceWindowsAuth.aspx">
<system.web>
<authorization>
<!-- will deny anonymous users -->
<deny users="?"/>
</authorization>
</system.web>
</location>
However this is still not working. It is denying everyone from viewing forceWindowsAuth.aspx with the message "Access is Denied"
The IIS site is configured for both anonymous and windows auth. I just cannot figure out how to force windows auth on one page only. Thank you before hand for your help.
The problem is whether you have seen "Allow all user" rule inherited from root level. As you can see I only have a deny rule for anonymous rule, but it will also inherit the allow all users rule. So it will promise only anonymous user will be blocked in this page and other user will not be blocked.
If there is only one "deny anonymous user", other user will never be able to view this page. If you don't set either deny or allow for a user, IIS will block the user by default.
Edit:
You can fix this by modifying the web.config like this.
<location path="forceWindowsAuth.aspx">
<system.webServer>
<security>
<authorization>
<clear/>
<add accessType="Allow" users="*" />
<add accessType="Deny" users="?" />
</authorization>
</security>
</system.webServer>
</location>

IIS URL Authorization check in ASP.Net

I have an ASP.Net web forms app running under IIS 7+
The entire app is currently secured using Windows Authentication and URL Authorization, configured in the web.config via IIS. The .NET doesn't care who the user is, there are no profiles or roles or anything at the moment.
<system.web>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Allow" roles="AppXUsers" />
<deny users ="?" />
</authorization>
</system.web>
I wish to add an additional page (in a subfolder), which will be accessible to subset of users, so I would modify the web.config like so:
<location path="mySubFolder">
<system.web>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Allow" roles="AppXPowerUsers" />
<deny users ="?" />
</authorization>
</system.web>
</location>
The client is free to then add or remove AD groups as they see fit.
However, as it stands users who are in the AppXUsers group but not in the AppXPowerUsers group still get shown links to the pages in mySubFolder. When they click the links they get access denied as it should be.
Is there any way I can detect whether or not the current user has access to "mySubFolder"?
I feel it would be a bit overkill to introduce User/RoleManagement at this stage - the application has no need to store any information relevant to users and it doesn't care who the user is beyond "can they access this page or not", which is currently handled at the IIS stage.
Take a look at this: http://msdn.microsoft.com/en-us/library/system.web.security.urlauthorizationmodule.checkurlaccessforprincipal.aspx
which is referenced here:
Determine if user can access the requested page?
UrlAuthorizationModule.CheckUrlAccessForPrincipal requires that the authorization rules are set in <system.web><authorization>
If you're introducing this into your web.config, though - why are you reluctant to use it in code?
Another way to check would be:
Context.User.IsInRole("somerole")

<authorization> can protect pages?

Can I use <authorization> to protect webforms from being accessed if a person does not have a specific role?
I tried this:
<authentication mode="windows" />
<authorization>
<allow roles="Admin" />
<deny users="*" />
</authorization>
but if the role Admin is not available then I can still visit the page by typing in the URL. How can I protect this page?
I read the documentation on MSDN (ASP.NET Authorization).
I also put the UrlAuthorizeModule extra in the web.config to make sure that it gets hit.
Best to read this: ASP.NET Authorization
It explains how to set the allow/deny elements for users and roles.

Multiple signin pages in one asp.net application

I have one asp.net web application.
It is using two membership provider.
Two sign-in pages one for each provider.
Now i have two folders in root Folder1 & Folder2
Folder1 uses 1st membership provider
Folder2 uses 2nd membership provider
I got almost everything working including signin, create user etc in both provider.
Only issue is in Form authentication i can define only one loginpath. So when session expires or need login to access secure pages. it can only redirct to one sign in page.
Also that section can't be defined by location. by application only.
How can i get folder2 to use 2nd sign in page?
if there is anything i can define by location?
See How to override/change FormsAuthentication LoginUrl in certain cases
It appears from various people researching, that you cannot tell FormsAuthentication to have two different Login pages. But there is nothing preventing you from creating some base page class or other code in your two folders that can determine which login page to direct to. Or, I think that the Application_BeginRequest event fires before the FormsAuthentication module fires, so you could examine requests before they get redirected by FormsAuthentication. Either way though, you would be forced to allow anonymous users to Folder1 and Folder2, which is not ideal.
You need to use the <location> element in your web.config. You can use the <location> tag to apply authorization settings to an individual file or directory.
<location path="/root">
<system.web>
<authentication mode="Forms" >
<forms name="LoginForm" defaultUrl="default.aspx"
loginUrl="/root/login.aspx" protection="Encryption"
timeout="30" path="/"/>
</authentication>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="/root/admin">
<system.web>
<authentication mode="Forms" >
<forms name="formName" defaultUrl="login.aspx"
loginUrl="/root/admin/login.aspx" protection="Encryption"
timeout="30" path="/"/>
</authentication>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
MSDN
For centralized administration,
settings can be applied in the
Machine.config file. The settings in
the Machine.config file define
machine-wide policy and can also be
used to apply application-specific
configuration using <location>
elements. Developers can provide
application-configuration files to
override aspects of machine policy.
For ASP.NET Web applications, a
Web.config file is located in the
application's virtual root directory
and optionally in subdirectories
beneath the virtual root.
If you would like 1 login location and different access levels you might want to use roles.
<location path="/root">
<system.web>
<authorization>
<allow roles="admin,root" />/*admin, root is allowed */
<deny users="*" />
</authorization>
<system.web>
</location>
<location path="/root/admin">
<system.web>
<authorization>
<allow roles="admin" />/*admin is allowed */
<deny users="*" />
</authorization>
<system.web>
</location>
Users can belong to more than one
role. For example, if your site is a
discussion forum, some users might be
in the role of both Members and
Moderators. You might define each role
to have different privileges on the
site, and a user who is in both roles
would then have both sets of
privileges.
You can access all these element at
the code level if you would like to
manipulate the roles/authentication
programmatically
Page.User.Identity.Name
Page.User.Identity.IsAuthenticated
Page.User.Identity.AuthenticationType
Page.User.IsInRole("string");
Additional Links
Using 2 Membership Providers in asp.net
4 Guys From Rolla Tutorial
The ASP.NET web.config File Demystified

ASP.NET Dynamic Data & Membership (Roles)

I am trying to setup roles in a dynamic data website..
the problem is that i cant set it by simpy doing this.
<location path="List.aspx">
<system.web>
<authorization>
<allow roles="Administrators" />
<deny users="*" />
</authorization>
</system.web>
</location>
so even when i login as a role called "Member" it still alows me to go into List.aspx
can any one please guide me on this..
oh btw i am also using mvc on the same site
Dynamic Data pages ignores all that jazz.
Look at the Secure Dynamic Data Project here:
http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14473
...
Or there is another way which worked for me.
Change your location path to:
<location path="Admin/<TableName>/List.aspx">
<system.web>
<authorization>
<allow roles="Administrators" />
<deny users="*" />
</authorization>
</system.web>
</location>
And then (in your global.asax.cs file) change your dynamic data route to:
routes.Add(new DynamicDataRoute("Admin/{table}/{action}.aspx")
This allowed me to provide table level security. If that doesn't work just make a comment and I'll look into again.
Your question as my friend said , needs more details ,
anyway
at first try to check whether you enabled Roles inside web.config or not .
Have you done this by WAT or not ? Try the alternative as a test .
3 . Set the authentication inside web.config to Forms .
hope to help
Regards
-MHM-

Resources