getting windows username with javascript

后端 未结 3 632
天涯浪人
天涯浪人 2021-01-15 13:18

I have a site which is built in ASP.net and C#. Let\'s call it webapp. it uses a Form system to log on into it, and cannot be changed easliy.

I got a request to chan

相关标签:
3条回答
  • The solution I found for getting the username sent to the server was:

    string winlogon = Request.ServerVariables["LOGON_USER"];
    

    After enabled Windows Authentication Mode in IIS.

    0 讨论(0)
  • 2021-01-15 13:44
    <script language="javascript">
        var username = '<%HttpContext.Current.User.Identity.Name %>';
    
    </script>
    
    0 讨论(0)
  • 2021-01-15 14:00

    The only way you could get at the user's domain credentials via javascript would be by deploying some type of ActiveX component to expose that data to the browser. I wouldn't recommend that.

    I would look at implementing a Login page for forms authentication that authenticates the user on the page load using HttpContext.Current.User.

    The way forms works is that if an unauthenticated user attempts to access an access-controlled page and have not logged in (no cookie), they will be redirected to a login page that gives the facility to log in (this sets a cookie on the client-side). The user is then directed to the page they initially requested. You would simply be automating the login part.

    If you have a mixture of pass-through and user who need to manually login you could check their client IP address to see if it matches one on your domain or not.

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