How to get the current login user name in my Script file inside my asp.net mvc

后端 未结 6 1125
谎友^
谎友^ 2020-12-10 14:02

I have a script file that makes a call to JSON API, and I need to send the current login username as part of the call. I tried the following :-

    $(documen         


        
6条回答
  •  甜味超标
    2020-12-10 14:46

        @User.Identity.Name
    

    You can directly access user identity in script section by prefixing @

        @User.FindFirst(ClaimTypes.NameIdentifier).Value
    

    also a good option.

提交回复
热议问题