可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a Silverlight application (using MVC) and when i'm building in visual studio, using Visual Studio Development center, there's no problem, the HttpContext.Current.User.Identity.Name
has a Value
But when i'm using the same project with IIS 7.5 (i'm using Windows 7), HttpContext.Current.User.Identity.Name
stays empty
Anyone who can help? Or knows where i can find the settings from the visual studio Development center, so i can check what's wrong in IIS?
回答1:
I struggled with this problem the past few days.
I suggest reading Scott Guthrie's blog post Recipe: Enabling Windows Authentication within an Intranet ASP.NET Web application
For me the problem was that although I had Windows Authentication enabled in IIS and I had <authentication mode="Windows" />
in the <system.web>
section of web.config, I was not preventing anonymous access. This last part was the key. You need to prevent anonymous access to ensure that the browser sends the credentials.
You can either configure IIS in Control Panel so that your site (or machine) uses Windows authentication and denies anonymous access or you can add the following to your web.config in the system.web section:
<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>
回答2:
These might resolve the issue(It did for me). In IIS Express change the project property values, "Anonymous Authentication" and "Windows Authentication". To do this, when project is selected, press F4 and then change these properties.
In case you are deploying it on IIS locally, make sure local machines "Windows Authentication" feature is enabled and "Anonymous Authentication" is disabled.
Refer to
https://grekai.wordpress.com/2011/03/31/httpcontext-current-user-identity-name-is-empty/
回答3:
Also, especially if you are a developer, make sure that you are in fact connecting to the IIS server and not to the IIS Express that comes with Visual Studio. If you are debugging a project, it's just as easy if not easier sometimes to think you are connected to IIS when you in fact aren't.
Even if you've enabled Windows Authentication and disabled Anonymous Authentication on IIS, this won't make any difference to your Visual Studio simulation.
回答4:
I also had this problem recently. Working with a new client, trying to get a an old web forms app running from Visual Studio, with IISExpress using Windows Authentication.
For me, the web.config was correctly configured
However, the IISExpress.config settings file had:
<windowsAuthentication enabled="false">
The user account the developer was logged in was very new, so unlikley it had been edited.
Simple fix it turned out, change this to enabled=true and it all ran as it should then.
回答5:
In addition to "answered Mar 28 '11 at 12:27Bryan Bedard"
In case that the solution doesn't work, you have to enable Windows Authentication in iss manager.
How to do that:
1.To start IIS Manager from the Run dialog box:
On the Start menu, click All Programs, click Accessories, and then click Run.
In the Open box, type inetmgr and then click OK.
2.In the Connections pane, expand the server name, expand Sites, and go to the level in the hierarchy pane that you want to configure, and then click the Web site or Web application.
3. Scroll to the IIS section in the Home pane, and then double-click Authentication.
4.In the Authentication pane, select Anonymous Authentication, and then click Disable.
- In the Authentication pane, select Windows Authentication, and then click Enable.
Reference
回答6:
The browser will only detect your username if the IIS server is on the same domain and the security settings within your group policy allow it.
Otherwise you will have to provide it with credentials, but if it is not on the same domain, it will not be able to authenticate you.
回答7:
As @PaulTheCyclist says, If using IISExpress anonymous authentication is enabled by default, windows authentication is disabled.
This can be changed in what I'm sure used to be called PropertyPages (NOT right-click -> properties). Select the web project
回答8:
Disabling all other options in authentication tab of iis except windows authentication resolved my issue.
Please check..
Steps:
- Open iis in your machine
- Select your application from the application pool
- Click on authentication option
- Disable all other option except windows authentication (Anonimous authentication should be disabled)
Please check this and let me know the feedback. It worked for me. hope it will work for you also..