Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Authentication

Status
Not open for further replies.

desi2002

Programmer
Jan 4, 2002
24
IN
Hi,
Does anybody know how to access windows nt user's credentials in an ASP program?
I want to find out the role, user group of an user who logs in to the system. I don't know how to use windowsprincipal.isinrole.
Please help.

Thanks

 
First you have to use IE.
In the IIS sevecis manager you have to set the direcotry security to integrated windows authentication (this part only works if users have IE).
This means that when a user visits your site the and the user is loged in on your network he or she will automatically send his or her login name.
You can get this login name with the following code:
User.Identity.Name
This will return a string (domain\username)
To see if a user is in a role you can use:
User.IsInRole("admin")

You can use the web.config file to allowe and deny users, the file will look like this:
<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?>
<configuration>
<system.web>
<authorization>
<deny users=&quot;*&quot; />
<allow users=&quot;boogiewoogie&quot; /> <!-- Allow all users -->
<!-- <allow users=&quot;[comma separated list of users]&quot;
roles=&quot;[comma separated list of roles]&quot;/>
<deny users=&quot;[comma separated list of users]&quot;
roles=&quot;[comma separated list of roles]&quot;/>
-->
</authorization>
</system.web>
</configuration>


You can find more info here:
 
Sorry, it seems that the isinrole is for forms varification so you must make the roles first than add users to it and then check if a user is in a role.
In asp I used to use hasaccess and let a group of nt users have access to file.
this is the code:
dim objFileSys
dim objFile
dim objChk
set objChk = server.CreateObject (&quot;MSWC.Permissionchecker&quot;)
set objFileSys = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
set objFile = objFileSys.GetFile(&quot;C:\Inetpub\if objChk.HasAccess(objFile) then
' this user is ok
end if

This way if I wanted to add/remove users to use an Intranet application I just added or removed them from the user group.
I have yet to find out how to do this with .net.
 
Thanks harmmeijer. But I want to know how to do this with .net.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top