|
-
Apr 17th, 2008, 01:35 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] passing role to the context user.
Hi,
We have a requirement that will authenticate against AD and to the database. We do this because not all user in AD will have an access to the application. The user in AD has no specific role. My question is it posible to add role to the context user dynamically? Thanks!
-
Apr 17th, 2008, 02:27 AM
#2
Re: passing role to the context user.
Yes, you'll simply have username stored against rolename in a table somewhere.
-
Apr 17th, 2008, 04:15 AM
#3
Thread Starter
Fanatic Member
Re: passing role to the context user.
Hi Mendhak,
I can now successfully override the context username and the role using the genericPrincipal class but when I set the web.config. Pls see the config below. Even the user is clerk still can access the page. Im user the role of the user is Clerk because I checked using the IsinRole method.
<
authorization>
<allow roles="Manager" />
<Deny roles="Clerk" />
</authorization>
-
Apr 17th, 2008, 04:50 AM
#4
Thread Starter
Fanatic Member
Re: passing role to the context user.
I have another problem the changes happened only on that context meaning it will reset if another request will be happen?
-
Apr 17th, 2008, 10:54 AM
#5
Re: passing role to the context user.
Oh, those roles.
It wasn't clear in your original post. The database would contain custom defined roles, it won't work like that, unless you create a role provider.
-
Apr 17th, 2008, 09:04 PM
#6
Thread Starter
Fanatic Member
Re: passing role to the context user.
Acutally I used a windows authentication if authentication was succesffully it will check to the user database if exist. Then if exist it will return a role then this role I want to override to the context user. I do this because our AD has no groups/roles.
-
Apr 18th, 2008, 01:41 AM
#7
Member
Re: passing role to the context user.
hmm.... i don't know whether this will help you out... my web.config looks like this
Code:
<authorization>
<allow roles ="admin"/>
<deny users ="*"/>
</authorization>
</system.web>
</location>
<location path="Admin/AddUsers.aspx">
<system.web>
and my login page for the role is
Code:
FormsAuthentication.SetAuthCookie(Login.Name, True)
If Roles.IsUserInRole(Login.Name, "admin") = False Then
Roles.AddUserToRole(Login.Name, "admin")
Response.Redirect("Admin.html")
As for me, i am using form authenication
Hope this can help you out..
-
Apr 18th, 2008, 01:44 AM
#8
Re: passing role to the context user.
Implement a custom membership provider that looks at the currently logged in user (windows auth) and checks the database for their role. This will mean that you need to store their name in the database in a table against a role or roles. Any new users who don't exist in that table will need to be added against a default role.
http://msdn2.microsoft.com/en-us/library/f1kyba5e.aspx
-
Apr 20th, 2008, 08:57 PM
#9
Thread Starter
Fanatic Member
Re: passing role to the context user.
Thanks for the rep guys but my problem now Im facing is that during that request, sample in the page load or init event I can succesfully override that user but when my page request to another server the value will reset to the actual login user. I realize that the overriding is per context meaing per request but I dont want to this that every request to server I have to override that user. I want a static value for this after I succesfully override that user.
-
Apr 22nd, 2008, 04:47 AM
#10
Re: passing role to the context user.
Override the user with what?
-
Apr 22nd, 2008, 09:01 PM
#11
Thread Starter
Fanatic Member
Re: passing role to the context user.
The role is from database and username from active directory
-
Apr 23rd, 2008, 02:21 AM
#12
Re: passing role to the context user.
Yes, but you said
in the page load or init event I can succesfully override that user but when my page request to another server the value will reset to the actual login user
Override the user with what?
-
Apr 23rd, 2008, 03:44 AM
#13
Thread Starter
Fanatic Member
Re: passing role to the context user.
Sorry for misunderstanding
If a user log in the site using basic authentication using user "userbasic" then if succesful. The user context now is "userbasic". In the page load in my page I have to query to the database the userbasic assuming both is exist in AD and database. In the database I have a field called role which I want to override the value in the user role in the context. I can succesfull override but the problem is per context meaning if I want to retain the role from database I have to override in each request.
I have to do this because the username from AD has no group or role. we have no authorize to alter the data from AD. That why we have to authencate from AD then override the role from database. Assuming that all user must exist in AD and database.
-
Apr 23rd, 2008, 07:59 AM
#14
Re: passing role to the context user.
Which is why you need to create your own custom membership provider, post #8, so that it can work with your other membership controls.
-
Apr 23rd, 2008, 08:11 PM
#15
Thread Starter
Fanatic Member
Re: passing role to the context user.
Thanks mendhak for the. I changed the authentication from windows to forms then create a login page. This solved my problem. Thanks for the idea.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|