Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC4 User.Identity.Name getting empty even though set authentication mode as 'Windows'

I am working on ASP.Net MVC-4 application. I have to implement windows authentication. I have set authentication mode as 'Windows' in web.config file as shown below.

     <system.web>
          <authentication mode="Windows" />
     </system.web>

In controller I try to get username as below.

    string userName = User.Identity.Name;

but every time I am getting empty value. Please let me know for any suggestions. Thanks in advance.

like image 410
user1755390 Avatar asked Feb 12 '23 09:02

user1755390


1 Answers

Windows authentication is performed by IIS to establish our managed code User.Identity. Therefore, you need to enable Windows Authentication in your IIS, and in order to force the user to authenticate before being able to access our application, you need to disable Anonymous Authentication

enter image description here

like image 67
Khanh TO Avatar answered Feb 15 '23 10:02

Khanh TO