Tabris42
asked on
ASP .NET/IIS6 NT User Impersonation problems..
Hi guys,
I've never really done this type of project before, but basically I want to have a site on our company's intranet website that will automatically utilize the visitor's NT domain credentials when they visit the page.
Now this little code snippet, if it works I should be golden:
currentWindowsIdentity = CType(User.Identity, System.Security.Principal. WindowsIde ntity) impersonationContext = currentWindowsIdentity.Imp ersonate() strUser = currentWindowsIdentity.Nam e.ToString .Substring (currentWi ndowsIdent ity.Name.T oString.In dexOf("\") + 1) Response.Write("You are validated on this page as: <B>" & strUser & "</B><BR>")
This works great when debugging through the ASP .NET Development Server on my work machine. It'll report my username and everything's good. However, when I move to production, it fails. Here's the error:
System.InvalidOperationExc eption: An anonymous identity cannot perform an impersonation. at System.Security.Principal. WindowsIde ntity.Impe rsonate(St ackCrawlMa rk& stackMark) at System.Security.Principal. WindowsIde ntity.Impe rsonate() at CCIWSignIn._Default.Page_L oad(Object sender, EventArgs e)
Now, I'm thinking this might have something to do with the way IIS works through the anonymous IUSR_servername account? So I disabled anonymous access for that page in IIS, and enabled "Integrated Windows Authentication", which just prompts me for a username and password that is doesn't seem to want to accept in the DOMAIN/Username fashion. So I've unchecked that and tried "Digest authentication for Windows domain servers". This prompts me for authentication, which I provide, and the code above works, but is there a way to just use my already entered login credentials and not get prompted for them by the site?
Any insight would be appreciated...
I've never really done this type of project before, but basically I want to have a site on our company's intranet website that will automatically utilize the visitor's NT domain credentials when they visit the page.
Now this little code snippet, if it works I should be golden:
currentWindowsIdentity = CType(User.Identity, System.Security.Principal.
This works great when debugging through the ASP .NET Development Server on my work machine. It'll report my username and everything's good. However, when I move to production, it fails. Here's the error:
System.InvalidOperationExc
Now, I'm thinking this might have something to do with the way IIS works through the anonymous IUSR_servername account? So I disabled anonymous access for that page in IIS, and enabled "Integrated Windows Authentication", which just prompts me for a username and password that is doesn't seem to want to accept in the DOMAIN/Username fashion. So I've unchecked that and tried "Digest authentication for Windows domain servers". This prompts me for authentication, which I provide, and the code above works, but is there a way to just use my already entered login credentials and not get prompted for them by the site?
Any insight would be appreciated...
ASKER
Yes, that was just a typo...
ASKER
I have found a workaround that works rather well... probably terrible for security though. This is to set "Basic authentication" for the folder in IIS. It still prompts for the username and password, however, so advice on how to avoid that and use the NT credentials already provided would be appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good idea about the SSL. I've configured it for that and am still using the basic authentication... fiddled with the NTFS permissions but still get prompted every time.
If I can't get away with letting the user login automatically... is there at least a way I can make the User field fill out with their domain\username? Then they just need to enter their password?
If I can't get away with letting the user login automatically... is there at least a way I can make the User field fill out with their domain\username? Then they just need to enter their password?
I'm not sure if that is a typo in your post or that's what you actually tried, but just to make sure... it should be a backslash and not a forward slash...
DOMAIN\Username