熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp.net獲得客戶端域賬號

2022-06-13   來源: .NET編程 

  To get the windows user name through programatically Compulsary we need to set the web server

  Open the Internet Infomation Services(IIS) Select your ASPNET Virtual Directory right click go to the Properties In Properties window go to Directory Security Tab Here You Find the Edit button in Anonymous access and Authentication Control Press Edit Button Now Authentication Methods dialogbox will appear

  In this dialog box by default it is set(checked) Anonymous Access uncheck this checkbox and go to botom of this dialog box check the Integrated windows authentication Here why we are selecting this Default web server is logged by ISUER_MachineName so if it is window authentication web server will take the credentials from windows logged user

  Getting the User Name :

  using three ways we can get the User Name using C#

  ) SystemSecurityPrincipalWindowsPrincipal p = SystemThreadingThreadCurrentPrincipal as SystemSecurityPrincipalWindowsPrincipal;

  string strName = pIdentityName;

  [ OR ]

  ) string strName = HttpContextCurrentUserIdentityNameToString();

  [ OR ]

  ) string strName = RequestServerVariables[AUTH_USER]; //Finding with name

  string strName = RequestServerVariables[]; //Finding with index

  In Above Cases returnin string contains DomainName\WinNTLoggedUserName

  (for Ex: Microsoft\BillGates Here Microsoft is domain BillGates is Logger User Name )

  Using string operations seperate the DomainName and UserName


From:http://tw.wingwit.com/Article/program/net/201311/13941.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.