Why does HttpContext.Current.User.Identity.Name return blank

前端 未结 5 1445
攒了一身酷
攒了一身酷 2020-12-17 20:06

I created a site. It is an internal site. It is a .NET 4.0 site. I would like to grab the username using HttpContext.Current.User.Identity.Name of the person browsing the

相关标签:
5条回答
  • 2020-12-17 20:31

    In IIS, go to Sites \ Default Website \ [Your Website].

    Select Authentication option and disable Anonymous Authentication.

    0 讨论(0)
  • 2020-12-17 20:32

    It comes up blank when unauthenticated. You can verify this by also doing:

    HttpContext.Current.User.Identity.IsAuthenticated
    

    Check your authentication level in IIS, is it set to enable windows authentication there too?

    0 讨论(0)
  • 2020-12-17 20:32

    In iis disable anonymous access and enable integrated windows security for you web application.

    0 讨论(0)
  • 2020-12-17 20:38

    Yes, you do need, at least the

    <authentication mode="Windows"></authentication>
    

    part is required if you are using Integrated Windows Auth.

    After that, you should be able to grab the username of the person logged in.

    No, you don't need:

    <validation validateIntegratedModeConfiguration="false" />
    
    0 讨论(0)
  • 2020-12-17 20:41

    In my case removing <remove name="FormsAuthentication" /> line from web.config helps.

    I also have <authentication mode="Forms" /> in <system.web> section.

    0 讨论(0)
提交回复
热议问题