locked
HttpContext.Current.User.Identity suddenly stopped working in visual studio 2017 RRS feed

  • Question

  • User184079159 posted
    I am using HttpContext.Current.User.Identity in my asp.net web application. Visual studio version is 2017.
    This piece of code suddenly stopped working & throwing null value.
    Can anyone help me to resolve this issue?
    Tuesday, December 4, 2018 3:03 AM

All replies

  • User-893317190 posted

    Hi VinitaJain,

    What authentication are you using in application?FormsAuthentication or WindowsAuthentication?

    Have your application thrown any error? 

    You say the code suddenly stopped and throw null value.

    Do you mean HttpContext.Current.User is null?

    If it is the case , you could refer to the link below

    https://stackoverflow.com/questions/1663535/httpcontext-current-user-is-null-even-though-windows-authentication-is-on

    Please post your web.config and your related code.

    Best regards,

    Ackerly Xu

    Wednesday, December 5, 2018 3:12 AM
  • User184079159 posted
    Hi Ackerly,

    I'm using Windows authentication in my web application & below piece of code is used to fetch the ID of currently logged in user.
    String ID = HttpContext.Current.User.Identity.ToString();
    Sunday, December 9, 2018 5:08 PM
  • User475983607 posted



    I'm using Windows authentication in my web application & below piece of code is used to fetch the ID of currently logged in user.
    String ID = HttpContext.Current.User.Identity.ToString();

    The behavior usually indicates Forms Authentication is enabled. Check your IIS configuration.

    It can also be due to a logical error where the Identity is checked outside of an HTTP request.

    Sunday, December 9, 2018 5:25 PM
  • User184079159 posted
    Hi mgebhard,

    This code works when application is hosted in IIS but I'm facing issue in local host & also, same piece of code was working fine few days back. Not sure why this issue suddenly. I didn't make any changes in the logic.
    Monday, December 10, 2018 3:44 AM
  • User475983607 posted

     

    This code works when application is hosted in IIS but I'm facing issue in local host & also, same piece of code was working fine few days back. Not sure why this issue suddenly. I didn't make any changes in the logic.

    Again, this behavior indicates an IIS (localhost) configuration issue.  Please check your configuration.

    Monday, December 10, 2018 12:52 PM
  • User184079159 posted
    Hi mgebhard,

    It would be helpful if you can guide me to correct those configurations.
    Monday, December 10, 2018 1:31 PM
  • User475983607 posted



    It would be helpful if you can guide me to correct those configurations.

    If the application is hosted in IIS then see IIS support documentation.

    https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/authentication/windowsauthentication/

    If the application is hosted in IIS Express then see the docs for IIS Express.

    https://www.danesparza.net/2014/09/using-windows-authentication-with-iisexpress/

    If this is an ASP.Core app then see the docs for Core.

    https://docs.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-2.2

    Monday, December 10, 2018 1:52 PM