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.
关键词标签:asp.net
相关阅读
热门文章
诛仙3飞升任务怎么做-诛仙3飞升任务流程最新2022
钟离圣遗物推荐-原神钟离圣遗物词条
解决方法:应用程序“DEFAULT WEB SITE”中的服务器错误
使用aspnet_regiis.exe 重新注册.NET Framework
人气排行 诛仙3飞升任务怎么做-诛仙3飞升任务流程最新2022 asp.net表单提交方法GET\POST 在ASP.NET中如何判断用户IE浏览器的版本 Asp.net中messagebox的实现方法 Asp.net中的web.config配置 在ASP.NET MVC中实现大文件异步上传 asp.net获取URL和IP地址 FileUpload上传多文件出现错误的解决方法
查看所有0条评论>>