IIS Impersonation

 

 Yesterday I was blocked with the problem that how to get the user's alias when he visit my website. Reminded by a friend, he told me that using the IIS Impersonation can implement this function. And then I start to search the reference about the IIS Impersonation, and config my configuraion file, after that I get the user name in the code, but found out that the data was wrong, everytime is return the string 'NT AUTHORITY/IUSR'. The reason is that the user visit the website with Anonymous Authentication. It is apparent that I have configuted the config well, then I try to find out the configuration windows, but fail as the win7 and Server 2008 don't have the same config windows. After a long tangled, I finally get it and implement the feature well. Here I document the config steps down:
 Firstly, config your web.config well:
    <authentication mode="Windows"/>
    <identity impersonate="true" />
 Secondly, config the IIS:
 
 For Win7/Server 2008:
  1. Click the web site in the IIS
  2. Click the  Authentication, then set the Anonymous Authentication disabled, ASP.Net Impersonation enabled, the Forms Authentication Disabled, Windows Authentication Enabled.
 
 For Server 2003:
   1. Open IIS Manager or add the IIS MMC snap-in to an existing management console.
   2. Expand the server that contains the Web site, virtual directory, or file that you want to configure authentication for, config it like above.
 
FYI, (Reference below is from http://stackoverflow.com/questions/1267071/how-to-get-windows-user-name-when-identity-impersonate-true-in-asp-net)
1) With <authentication mode="Windows"/> in your application and Anonymous access enabled in IIS, you will see the following results:
System.Environment.UserName: Computer Name
Page.User.Identity.Name: Blank
System.Security.Principal.WindowsIdentity.GetCurrent().Name: Computer Name
2) With <authentication mode="Windows"/> in your application, and ‘Anonymous access’ disabled and only ‘Integrated Windows Authentication’ in IIS, you will see the following results:
System.Environment.UserName: ASPNET (user account used to run ASP.NET service)
Page.User.Identity.Name: Domain/ Windows Account Name
System.Security.Principal.WindowsIdentity.GetCurrent().Name: Computer Name/ASPNET
3) With <authentication mode="Windows"/> and <identity impersonate ="true"/> in your application, and ‘Anonymous access’ disabled and only ‘Integrated Windows Authentication’ in IIS, you will see the following results:
System.Environment.UserName: Windows Account Name
Page.User.Identity.Name: Domain/ Windows Account Name
System.Security.Principal.WindowsIdentity.GetCurrent().Name: Domain/ Windows Account Name

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值