Click here to Skip to main content
15,886,770 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to authenticate users using Active directory credential and no need to enter user name and password. simply type url in browser and it will authenticate by windows credential of Active directory.

What I have tried:

public string GetCurrentUserWindowsLogin()
		{

			string windowsLogin = Page.User.Identity.Name;
			//Normally if the domain is present you get a string like DOMAINNAME\username, remove the domain
			int hasDomain = windowsLogin.IndexOf(@"\");
			if (hasDomain > 0)
			{
				windowsLogin = windowsLogin.Remove(0, hasDomain + 1);
			} //end if 
			return windowsLogin;
		} //end GetCurrentUserWindowsLogin
Posted
Updated 15-Jun-17 7:22am
Comments
F-ES Sitecore 15-Jun-17 4:18am    
You need to configure your site to use Windows Authentication

https://technet.microsoft.com/en-us/library/cc754628(v=ws.10).aspx

Google for other walkthroughs if that one doesn't help. Note there are numerous caveats to this working, it won't work over the internet, you can't also have anonymous authentication enabled and so on.
ZurdoDev 15-Jun-17 7:15am    
Don't write any code. Use Windows Authentication in web.config.
Member 1151556 26-Feb-19 1:08am    
Hi ZurdoDev, please tell me about how to config in file
Vikram Singh Rathaur 15-Jun-17 7:47am    
it's not working for me.
Vikram Singh Rathaur 15-Jun-17 7:47am    
i am using below code


<authentication mode="Windows" />
<authorization>
<deny users="?" />

<identity impersonate="false" />

1 solution

If your users are in the same domain as your server, you can make this work.
  • For Internet Explorer, the user needs to add your site to the "Local Intranet" zone, as it only sends their Windows credentials to sites in that zone;
  • For Chrome, the user also needs to add your site to IE's "Local Intranet" zone. All recent versions of Chrome will use the IE zones to control automatic Windows authentication.
  • For Firefox, the user will need to open about:config, and add your site to the network.automatic-ntlm-auth.trusted-uris setting.

    Multiple sites can be specified, separated with a comma.

    They may also need to add your site to the network.negotiate-auth.delegation-uris and network.negotiate-auth.trusted-uris settings, depending on their setup.

    Alternatively, they could install the Integrated Authentication for Firefox[^] add-on to manage the list via a friendlier GUI.


If your users are not in the same domain as your server, then you cannot do this.
 
Share this answer
 
Comments
Vikram Singh Rathaur 16-Jun-17 1:28am    
In this case, we need to change system browser setting for every individual users.
Richard Deeming 16-Jun-17 8:06am    
Yes. But if they're all part of the same domain, the IE / Chrome settings can be managed via Group Policy.
Vikram Singh Rathaur 19-Jun-17 2:20am    
Thanks. Its working fine in IE & Chrome but in firefox its prompt me login pop up.i have already added in about:config, and add site to the network.automatic-ntlm-auth.trusted-uris
Richard Deeming 19-Jun-17 6:04am    
Try using the add-on to change the settings on one machine, and then look at the config setting. It's quite picky, so it's possible you've not got it in precisely the right format.
Vikram Singh Rathaur 19-Jun-17 6:42am    
i have added network.automatic-ntlm-auth.trusted-uris and now its working fine for me. now how we will add on all users machine in same domain.

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