IT貓撲網(wǎng):您身邊最放心的安全下載站! 最新更新|軟件分類(lèi)|軟件專(zhuān)題|手機(jī)版|論壇轉(zhuǎn)貼|軟件發(fā)布

您當(dāng)前所在位置:首頁(yè)網(wǎng)絡(luò)編程.Net編程 → asp.net獲得客戶端域賬號(hào)

asp.net獲得客戶端域賬號(hào)

時(shí)間:2015/6/28來(lái)源:IT貓撲網(wǎng)作者:網(wǎng)管聯(lián)盟我要評(píng)論(0)

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

  Open the Internet Infomation Services(iis), Select your ASP.NET 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#

  1) System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;

  string strName = p.Identity.Name;

  [ OR ]

  2) string strName = HttpContext.Current.User.Identity.Name.ToString();

  [ OR ]

  3) string strName = Request.ServerVariables["AUTH_USER"]; //Finding with name

  string strName = Request.ServerVariables[5]; //Finding with index

  In Above 3 Cases returnin string contains DomainName\WinNTLoggedUserName

  (for Ex: Microsoft\Bill.Gates. Here Microsoft is domain Bill.Gates is Logger User Name )

  Using string operations seperate the DomainName and UserName.

關(guān)鍵詞標(biāo)簽:asp.net

相關(guān)閱讀

文章評(píng)論
發(fā)表評(píng)論

熱門(mén)文章 手把手教你用好LINQ to SQL手把手教你用好LINQ to SQL在.NET環(huán)境下為網(wǎng)站增加IP過(guò)濾功能在.NET環(huán)境下為網(wǎng)站增加IP過(guò)濾功能ASP.NET 如何避免頁(yè)面重新整理時(shí)重復(fù)送出ASP.NET 如何避免頁(yè)面重新整理時(shí)重復(fù)送出用Asp.net擴(kuò)展ExtJS用Asp.net擴(kuò)展ExtJS

相關(guān)下載

人氣排行 asp.net表單提交方法GET\POST在ASP.NET中如何判斷用戶IE瀏覽器的版本Asp.net中messagebox的實(shí)現(xiàn)方法Asp.net中的web.config配置在ASP.NET MVC中實(shí)現(xiàn)大文件異步上傳用Iformattable接口控制.Net中文本格式c#.Net經(jīng)典面試題目用Asp.net擴(kuò)展ExtJS