开发者

HttpContext, WindowsIdentity, Thread on Anonymous IIS

I've worked at this quite a bit, but cannot seem to find a good solution.

I have a ASP.NET app (.Net 3.5) with IIS which pulls the user machine name and username from the account. This works on my local machine, but when uploading using IIS it gives null or IIS APPPOOL/appname. On IIS I have "Integrated Windows Authentication" and "Anonymous" set and in my Web.config file

<authentication mode="Windows"/>
<identity impersonate="true"/>

And I am trying to access the user information a number of different ways, some are:

HttpContext.Current.User.Identity.Name
System.Threading.Thread.CurrentPrincipal.Identity.Name
System.Securi开发者_开发技巧ty.Principal.WindowsIdentity.GetCurrent().Name
Environment.UserName

Each of these work on my local machine, but when uploaded to the IIS server, everything gives invalid information. The app is internal, but I still need it to grab the Username without giving a login screen. Ideas?

Update: I've changed IIS to Anonymous Authentication Disabled and Windows Auth Enabled. And my web.config file I've tried the following

<authentication mode="Windows"/>
<!-- <identity impersonate="true"/> -->

<authorization>
  <deny users="?"/>
  <allow users="*"/>
</authorization>

Sorry about the update, but are there any ideas?

For anyone following this and needing an answer, the problem lies in IIS. In the Authentication area in IIS only have ASP.NET Impersonation and Windows Authentication enabled, the others should be disabled. And in Windows Authentication, go to Advanced Settings and UNCHECK the Enable Kernel-mode authentication. The Authorization Rules area should allow for all users (note this is done in IIS, not in the config file) And the following code in config is necessary.

<system.web><authentication mode="Windows"/><identity impersonate="true"/></system.web>

Hope this helps someone, here's a couple links that helped me. Good luck!

http://msdn.microsoft.com/en-us/library/aa302377.aspx

http://www.eggheadcafe.com/tutorials/aspnet/1f12cd61-6bb3-4ffd-bac1-124d40837006/aspnet-request-identity--an-analysis.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜