0

I'm writing an ASP.NET v4.5.2 Windows Application / Windows Form for our sales team to use and I don't want them to have to log in. I want to compare their windows domain/userid to a userid that I have in a database for authentication. I can get the domain/userid to display correctly in Visual Studio by using:

string userLogin = Request.LogonUserIdentity.Name;

But when I deploy the application to our server this is what is displayed:

NT AUTHORITY\IUSR

The server is 2012 running IIS 8 and here are the settings for this web page:

Anonymous Authentication: Enabled
ASP.NET Impersonation:    Disabled
Basic Authentication:     Enabled
Digest Authentication:    Disabled
Forms Authentication:     Disabled
Windows Authentication:   Enabled

I've read this: Get Domain User ID in ASP.NET and followed the instructions but run across problems.

The first problem is that when I Disable Anonymous Authentication in IIS I get a 404 - File or directory not found error.

Another problem is that when I put this tag in web.config

<authorization>
 <deny users="?"/>
</authorization>

I also get the 404 error.

I have also changed authentication mode in web.config to this:

<authentication mode="Windows" />

And still get the 404 or incorrect domain/user information (depending on the IIS settings).

I've started a project named test just to debug this problem.

When I disable Anonymous Authentication in IIS the url changes to this: servername/test/Account/Login?/ReturnUrl=%2Ftest%2FAccount%2FLogin%3FReturnUrl%3D%252Ftest%252FAccount%252FLogin%253FReturnUrl%253D%25252Ftest%25252FAccount%25252FLogin%25253FReturnUrl%25253D%2525252Ftest%2525252FAccount%2525252FLogin%2525253FReturnUrl%2525253D%252525252Ftest%252525252FAccount%252525252FLogin%252525253FReturnUrl%252525253D%25252525252Ftest%25252525252FAccount%25252525252FLogin%25252525253FReturnUrl%25252525253D%2525252525252Ftest%2525252525252FAccount%2525252525252FLogin%2525252525253FReturnUrl%2525252525253D%252525252525252Ftest%252525252525252FAccount%252525252525252FLogin%252525252525253FReturnUrl%252525252525253D%25252525252525252Ftest%25252525252525252FAccount%25252525252525252FLogin%25252525252525253FReturnUrl%25252525252525253D%2525252525252525252Ftest%2525252525252525252FAccount%2525252525252525252FLogin%2525252525252525253FReturnUrl%2525252525252525253D%252525252525252525252Ftest%252525252525252525252FAccount%252525252525252525252FLogin%252525252525252525253FReturnUrl%252525252525252525253D%25252525252525252525252Ftest%25252525252525252525252FAccount%25252525252525252525252FLogin%25252525252525252525253FReturnUrl%25252525252525252525253D%2525252525252525252525252Ftest%2525252525252525252525252FAccount%2525252525252525252525252FLogin%2525252525252525252525253FReturnUrl%2525252525252525252525253D%252525252525252525252525252Ftest%252525252525252525252525252FAccount%252525252525252525252525252FLogin%252525252525252525252525253FReturnUrl%252525252525252525252525253D%25252525252525252525252525252Ftest%25252525252525252525252525252FAccount%25252525252525252525252525252FLogin%25252525252525252525252525253FReturnUrl%25252525252525252525252525253D%2525252525252525252525252525252Ftest%2525252525252525252525252525252FAccount%2525252525252525252525252525252FLogin%2525252525252525252525252525253FReturnUrl%2525252525252525252525252525253D%252525252525252525252525252525252Ftest%252525252525252525252525252525252FAccount%252525252525252525252525252525252FLogin%252525252525252525252525252525253FReturnUrl%252525252525252525252525252525253D%25252525252525252525252525252525252Ftest%25252525252525252525252525252525252F

Keep in mind that I'm writing my own login and not using .NET's.

My apologies if this is a duplicate question but I've done a lot of reading on here and other blogs and still get the same behavior no matter what I try.

Thanks in advance for the help.

Community
  • 1
  • 1
CuriousOne
  • 51
  • 10
  • I hope you got solution here. please refer this [url](http://stackoverflow.com/questions/16184685/how-do-i-get-the-currently-loggedin-windows-account-from-an-asp-net-page). – Sudhakar Rao Feb 08 '17 at 19:57
  • @Sudhakar when I use System.Security.Principal.WindowsIdentity.GetCurrent().Name.Tostring() I get a HTTP Error 404.15 - Not Found error. The url is too long. I then changed the httpRuntime in web.config to: maxQueryStringLength="2097151" maxUrlLength="65536" enable="true" and still get the 404.15 error. – CuriousOne Feb 08 '17 at 20:07
  • Disable anonymous and basic. – mason Feb 08 '17 at 20:15
  • @mason: I have set Anonymous Authentication and Basic Authentication both to disabled and get 404 - File or directory not found. – CuriousOne Feb 08 '17 at 20:28
  • Then have you made you're requesting the right directory? What URL are you requesting? What directory if the root of your site? What does your site's file structure look like? – mason Feb 08 '17 at 20:28
  • I have a directory called test as the root that I created just to troubleshoot this problem. It is in wwwroot and it will display the site if Anonymous Authentication is set to Enabled only. As soon as I disable it, I can't display the site. I think it has to do with the length of the url when I disable Anonymous Authentication. – CuriousOne Feb 08 '17 at 20:31
  • Then show that error in your question. Sounds like a redirect loop. – mason Feb 09 '17 at 02:44
  • "The first problem is that when I Disable Anonymous Authentication in IIS I get a 404 - File or directory not found error." was in my question. – CuriousOne Feb 09 '17 at 12:50

0 Answers0