Click here to Skip to main content
15,886,707 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

I am developing a project in which Client requires a windows authentication. This simply means that if once user has logged on to the organizational domain that he should be able to open the application without asking for any password and if some user tries to hit the same application outside the domain than he should not be able to access the application.

I was able to achieve this on my local server and local machine but when I deployed my application on IIS I was not able to get the same. I was getting a error that I cannot retrieve the user principal name from the user certificates.


I used following approach :
C#
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

              // This code runs as the application pool user



          // find currently logged in user
          UserPrincipal user = UserPrincipal.Current;

          if (user.Certificates != null)
          {
              strfirstname = user.UserPrincipalName;
          }


I will be really thankful for any suggestion.

Regards,
Taresh
Posted
Comments
ZurdoDev 10-Apr-13 10:15am    
You would have to enable windows auth in IIS and disable anonymous access.
Taresh Uppal 11-Apr-13 1:14am    
I have already done that !
ZurdoDev 11-Apr-13 7:33am    
Use HttpContext.Current.Request.ServerVariables["LOGON_USER"] to get the username then.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900