0

Windows Authentication seems super simple, but I am still having trouble. So I decided to create a brand new Asp web app project with the Windows Authentication template. Of course, this works. In the designer, <asp:LoginName runat="server" /> works, and in code-behind User.Identity.Name works.

The only setting I can find is in web.config: <authentication mode="Windows"/>.

Back to my own web app project, I verified that I have the same web.config setting. However, the asp.LoginName tag and the User.Identity property have a blank string, i.e., no user name. Also, when using <deny users="?"/> the page returns a 401.2 Access Denied response.

As I am testing both projects on the same dev machine, both in VS2015, the problem cannot be in settings of IIS Express or VS2015. Also using the same Firefox browser, although I also tried IE.

Is there a project setting in VS2015 that I overlooked?


Update:

I kind of solved this issue by copying all project source files to the brand new Asp web app project. In fact, I was in the process of converting a Web Site project to a Web Application project. I still do not know why I could not get Windows Authentication to work by configuration, but at least I can get going with further development.

However, I am still hoping for an answer . . . :-)

Roland
  • 4,619
  • 7
  • 49
  • 81

2 Answers2

0

On your Web.config you must add:

<authentication mode="Windows" />

Your server must be a member of AD.

Check: https://support.microsoft.com/en-us/help/323176/how-to-implement-windows-authentication-and-authorization-in-asp-net

Godinho
  • 141
  • 1
  • 1
  • 4
  • I have that line in web.config. My dev pc is a member of the domain. In fact, on my dev pc, one project is working fine with Windows Authentication, but the other project not, and I cannot find the decisive difference. – Roland Feb 12 '18 at 16:07
  • Are you sure you have the config lin on the correct place? Should be something like: ` ` Also check: codeproject.com/Articles/94612/Windows-Authentication – Godinho Feb 14 '18 at 10:11
  • Yes, thanks. The intelli-sense of VisualStudio knew the keyword on that location of web.config. – Roland Feb 14 '18 at 15:03
0

You can write whatever you want in web.config, but if the desired mode of authentication is not enabled in [solution]/.vs/config/applicationhost.config , it will not work. Because the leading dot makes this a hidden path, this config is hard to find. No idea if this is a bug or a feature ...

See also my other question on another test case of this problem: https://stackoverflow.com/a/48806942/1845672

Roland
  • 4,619
  • 7
  • 49
  • 81