开发者

How can I get client machine user login in ASP.net?

On Localhost my username is 'MTA' when calling this code:

string opl = HttpContext.Current.User.Identity.Name.ToString();
TextBox1.Text = opl.Substring(opl.IndexOf(@"\") + 1);

OR this code:

string opl = System.Environment.Us开发者_如何学CerName.ToString();
TextBox1.Text = opl.Substring(opl.IndexOf(@"\") + 1);

But after publishing and accessing the website from a Windows Server. My username is now 'SRVCMAN'.


For this to work go into IIS click on Authentication and disable Anonymous Authentication and enable Windows Authentication

And then use this code:

var ident = (System.Security.Principal.WindowsIdentity)HttpContext.Current.User.Identity;
If(!ident.IsAnonymous && ident.IsAuthenticated)
{
  var loginUsername = ident.Name;
}


    // will return the host name making the request

    string s = Request.ServerVariables["REMOTE_HOST"] ;
-----------------------------------------------------------------
    // will return the computer name

    string s = Request.ServerVariables["SERVER_NAME"] ;
-----------------------------------------------------------------
   //will return Windows account for the user.

    string s = Request.ServerVariables["AUTH_USER"] ;
-----------------------------------------------------------------

I think you try to get information like this:

IIS Server Variables


I believe you are looking for implementing Windows Authentication Mode.
Refer to the following articles and read about it:

  • How To: Use Windows Authentication in ASP.NET 2.0
  • Explained: Windows Authentication in ASP.NET 2.0
  • How to implement Windows authentication and authorization in ASP.NET
  • Authenticating Users with Windows Authentication
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜