Steve Rudenko

Steve Rudenko

  • NA
  • 1
  • 1.3k

WebMatrix Razor IIS Windows Authentication Issue

Jun 11 2014 10:56 PM
I have a Razor/WebMatrix page on our intranet running on Windows Server 2008 R2 / IIS 7.5.
I need to be able to get the domain username of the person who loads the webpage. I tried disabling Anonymous Authentication and enabling Windows Authentication in IIS. Then in my page I added the following code to get the username: var current_user = Environment.UserName;
 
This worked for a few minutes but then the people who I asked to test started telling me that they are getting error 404 – Page Not Found
I refreshed the page and got the same error and noticed that the URL automatically goes to: /Account/Login?ReturnUrl=
 
On my IIS I just have 1 site – Default Web Site
Underneath it I have various sub-folders one of which is called CSHTMLPages. I am just trying to get Windows Authentication to work for pages in the CSHTMLPages folder. I don’t want users to login. Everyone is on the internal domain. All I need is to get their username instead of seeing DefaultAppPool or IUSR.
 
I searched online all day today and tried all possible suggestions but nothing seems to work.
Can someone please guide me how to get Windows Authentication to work with Razor so that I can get the visitors username (without having them login).
 
Thanks