HttpContext.Current.User.Identity.Name 为空

发布于 2024-08-07 07:48:31 字数 319 浏览 8 评论 0原文

我有一个 Silverlight 应用程序(使用 MVC),当我使用 Visual Studio 开发中心在 Visual Studio 中构建时,没有问题,HttpContext.Current.User.Identity.Name 有一个值,

但是当我在 IIS 7.5 中使用同一项目时(我使用的是 Windows 7),HttpContext.Current.User.Identity.Name 保持为空

有人可以提供帮助吗?或者知道我可以在哪里找到 Visual Studio 开发中心的设置,以便我可以检查 IIS 中的问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

゛时过境迁 2024-08-14 07:48:32

过去几天我一直在努力解决这个问题。

我建议阅读 Scott Guthrie 的博客文章 配方:在 Intranet ASP.NET Web 应用程序中启用 Windows 身份验证

对我来说,问题是虽然我在 IIS 中启用了 Windows 身份验证,并且我有 < ;authentication mode="Windows" /> 在 web.config 的 部分中,我没有阻止匿名访问。最后一部分是关键。 您需要阻止匿名访问以确保浏览器发送凭据。

您可以在控制面板中配置 IIS,以便您的站点(或计算机)使用 Windows 身份验证并拒绝匿名访问,或者您可以添加以下是 system.web 部分中的 web.config:

<authentication mode="Windows" />

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

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>
-小熊_ 2024-08-14 07:48:32

这些可能会解决问题(对我来说是这样)。在 IIS Express 中,更改项目属性值“匿名身份验证”和“Windows 身份验证”。为此,请在选择项目后按 F4,然后更改这些属性。

确保启用本地计算机的“Windows 身份验证”功能并禁用“匿名身份验证”。

请参阅

https://grekai。 wordpress.com/2011/03/31/httpcontext-current-user-identity-name-is-empty/

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.

enter image description here

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/

内心荒芜 2024-08-14 07:48:32

除了“2011 年 3 月 28 日 12:27Bryan Bedard 回答”之外,

如果该解决方案不起作用,您必须在 iss 管理器中启用 Windows 身份验证。
如何做到这一点:

1.从“运行”对话框启动 IIS 管理器:
在“开始”菜单上,单击“所有程序”,单击“附件”,然后单击“运行”。
在“打开”框中,键入 inetmgr,然后单击“确定”。

2. 在“连接”窗格中,展开服务器名称,展开“站点”,转到层次结构窗格中要配置的级别,然后单击网站或 Web 应用程序。
3. 滚动到主页窗格中的 IIS 部分,然后双击“身份验证”。

4.在“身份验证”窗格中,选择“匿名身份验证”,然后单击“禁用”。
输入图像描述此处

  1. 在“身份验证”窗格中,选择“Windows 身份验证”,然后单击“启用”。

参考

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.
enter image description here

  1. In the Authentication pane, select Windows Authentication, and then click Enable.

Reference

书间行客 2024-08-14 07:48:32

禁用 iis 身份验证选项卡中除 Windows 身份验证之外的所有其他选项解决了我的问题。
请检查..

步骤:

  1. 在您的计算机中打开iis
  2. 从应用程序池中选择您的应用程序
  3. 单击身份验证选项
  4. 禁用除 Windows 身份验证之外的所有其他选项(应禁用匿名身份验证)

请检查此项并告诉我反馈。这对我有用。希望它也对你有用..
输入图像描述这里

Disabling all other options in authentication tab of iis except windows authentication resolved my issue.
Please check..

Steps:

  1. Open iis in your machine
  2. Select your application from the application pool
  3. Click on authentication option
  4. 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..
enter image description here

若相惜即相离 2024-08-14 07:48:32

我最近也遇到了这个问题。使用新客户端,尝试使用 Windows 身份验证通过 IISExpress 从 Visual Studio 运行旧的 Web 表单应用程序。
对我来说,web.config 已正确配置

但是,IISExpress.config 设置文件具有:

<windowsAuthentication enabled="false">

开发人员登录的用户帐户非常新,因此不太可能已被编辑。
事实证明,修复很简单,将其更改为enabled=true,然后一切都按预期运行。

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 unlikely it had been edited.
Simple fix it turned out, change this to enabled=true and it all ran as it should then.

云之铃。 2024-08-14 07:48:32

另外,特别是如果您是开发人员,请确保您实际上连接到 IIS 服务器,而不是 Visual Studio 附带的 IIS Express。如果您正在调试一个项目,有时您会很容易认为自己已连接到 IIS,而实际上并未连接到 IIS。

即使您在 IIS 上启用了 Windows 身份验证并禁用了匿名身份验证,这也不会对您的 Visual Studio 模拟产生任何影响。

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.

幸福还没到 2024-08-14 07:48:32

仅当 IIS 服务器位于同一域且组策略中的安全设置允许时,浏览器才会检测您的用户名。

否则,您将必须向其提供凭据,但如果它不在同一域中,它将无法对您进行身份验证。

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.

寂寞美少年 2024-08-14 07:48:32

除了前面提到的所有明显原因之外,可能还有另一个原因:您没有在控制器顶部放置 Authorize 属性,如下所示:

[Authorize(Roles = "myRole")]
[EnableCors(origins: "http://localhost:8080", headers: "*", methods: "*", SupportsCredentials = true)]
public class MyController : ApiController

至少这对我有用。

Apart from all obvious reasons mentioned earlier, there might be another one: you didn't put an Authorize attribute on top of your controller, like that:

[Authorize(Roles = "myRole")]
[EnableCors(origins: "http://localhost:8080", headers: "*", methods: "*", SupportsCredentials = true)]
public class MyController : ApiController

At least that's what worked for me.

我三岁 2024-08-14 07:48:32

正如 @PaulTheCyclist 所说,如果默认启用 IISExpress 匿名身份验证,则 Windows 身份验证将被禁用。

这可以在我确信曾经被称为 PropertyPages 的内容中进行更改(不是右键单击 -> 属性)。选择网络项目

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

﹉夏雨初晴づ 2024-08-14 07:48:32

尝试在 IIS 中启用基本身份验证并禁用其他身份验证,然后尝试启动应用程序。该应用程序将要求提供 Windows 凭据。输入相同的内容,应用程序应该能够获取 HttpContext.Current.User.Identity.Name 下的名称。

Try enabling basic authentication and disabling the other authentications in IIS, then try launching the application. The application will ask for windows credentials. Enter the same and the app should be able to get the name under HttpContext.Current.User.Identity.Name.

听风念你 2024-08-14 07:48:32

当创建项目时未设置身份验证模式时,我遇到了这个问题。
因此,当创建一个新项目并在初始设置中将身份验证设置为 Windows 模式时,它就起作用了。

I was facing this issue when authentication mode was not set while creating the project.
So It worked when created a new project with authentication set to windows mode in the initial settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文