User.Identity.Name blank in ASP.Net MVC

前端 未结 4 877
-上瘾入骨i
-上瘾入骨i 2020-12-11 00:45

Exactly as per the title.

Simply in my HomeController I have:

string Username = User.Identity.Name;

Why is this value always blank?

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 01:23

    Sure is mate. You need to authenticate with the website. That's the name used for authentication.

    You are authenticating, right?

    It's not a setting, etc.

    Click the LOG IN link, if you're using the stock standard ASP.NET MVC template (if my memory serves me right).

    UPDATE (as the posted has added more info/comments)

    So what you're after is Windows Authentication. A quick google search came up with this post. It's pretty helpful (though a bit old, but still relevant) .. check that out.

    Found a better post with MVC code for Windows Authentication. Check that out instead.

    Config setting that is important, is...

    ...
     
      ...
      
      ...
     
     ...
    

提交回复
热议问题