locked
User.identity and user.identity.name is null for only one user RRS feed

  • Question

  • User-303331888 posted

    Hi,
    User.Identity and User.Identity.Name is null for only one user while fetching the user id with domain in .cshtml page. But the same thing (User.Identity.Name) is working fine in one HTML page. In .cshtml page it was used under script section but in HTML page it was used under body section. This is the only difference i have seen in these two pages.
    Is there any alternative to fetch user id with domain? or Could you please help me to fix this issue for that user alone?

    Thursday, June 18, 2020 10:38 AM

All replies

  • User753101303 posted

    Hi,

    I believe I never saw this behavior. You are 100% that User.Identity itself is null? I would start by looking if User.Identity.IsAuthenticated is false. You are using Windows authentication ?

    Edit: I believe to have seen you can have issues being of the "lsa cache" for example if a SamAccountName is changed etc...

    Thursday, June 18, 2020 11:55 AM
  • User-303331888 posted

    yes User.Idenity is null. For testing it, i put two alert boxes in cshtml page where user is getting issue. One is for returning User.Identity value and another one for returning User.Identity.Name value. When user accessing the page, both alert box didn't pop up. 

    Yeah am using windows authentication only.

    Edit: I believe to have seen you can have issues being of the "lsa cache" for example if a SamAccountName is changed etc...
     

    As far as i know user domain has been changed due to organisational change but not SamAccountName.

    Friday, June 19, 2020 1:55 PM
  • User475983607 posted

    If Windows authentication is enabled then the user should not be able to access the page at all.  Do you have anonymous access enabled?  

    Friday, June 19, 2020 2:18 PM
  • User753101303 posted

    Rajkumar31391

    both alert box didn't pop up

    To me it's inconclusive. You should see at least the first alert  and for now it sounds rather than you have some other error before reaching this point (you mean a JavaScript alert?).

    I would use the VS debugger to just look at the value or at worst I would trace User.Identity==null expecting to see either true or false. If it doesn't happen I would look for an earlier exception or would use User==null to be 100% sure if User is null as well or not.

    IMO making 100% sure about what happens is really important to avoid going into a wrong direction. In my experience, I can solve a problem much more quickly by investing first few extra minutes to get an exact understanding about what happens.

    Friday, June 19, 2020 2:36 PM