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

后端 未结 6 1134
谎友^
谎友^ 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:32

    $(document).ready(function () {
        var name = prompt("Please enter your packageid", "test");
    
        var fullurl = 'http://localhost:8080/jw/web/json/workflow/process/list?j_username=kermit&hash=9449B5ABCFA9AFDA36B801351ED3DF66&loginAs=' + <%= HttpContext.Current.User.Identity.Name %> + 'packageId=' + name;
        $.ajax({
            type: "GET",
            url: fullurl,
            dataType: "JSONP",
            success: function (result) {
    

    the above code should work, on the javascript front you will not have access to HTTPContent object which is available only on the server, but putting them in a server code you should be able to access the same.

    or you can have a hidden control with the value set from the server

    
    

    server code would look like

    uid.value = HTTPContext.Current.User.Identity.Name;
    

提交回复
热议问题