在 ASP .NET 3.5 中设置 Windows 身份验证

发布于 2025-01-08 20:11:21 字数 378 浏览 0 评论 0原文

这是我想做的事情(我以前做过,但我显然正在做一些对我来说并不明显的事情......):

  • ASP .NET 3.5 Intranet 应用程序
  • 想要在网站上针对 AD 设置进行 Windows 身份验证
  • 当用户请求页面时,使用以下代码获取用户的用户名:

    System.Web.HttpContext.Current.User.Identity.Name

I拥有 IIS 7.5 并已设置 Web 应用程序、禁用匿名访问并启用 Windows 身份验证。

当请求该页面时,将提示输入用户名/密码。

我输入了详细信息,但提示不断出现,最终返回 401。

我到底错过了什么?

Here's what I want to do (which I've done before but I'm clearly doing something that is not obvious to me...):

  • ASP .NET 3.5 Intranet Application
  • Want to have Windows Authentication against AD setup on the website
  • When the user requests the page, fetch the user's username with the following code:

    System.Web.HttpContext.Current.User.Identity.Name

I have IIS 7.5 and have setup the web application, disabled anonymous access and enabled Windows Authentication.

When the page is requested, the prompt for username / password is entered.

I entered the details but the prompt keeps coming up and eventually comes back with 401.

What on earth have I missed?

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

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

发布评论

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

评论(2

粉红×色少女 2025-01-15 20:11:21

这似乎是授权的问题(不要与身份验证混淆,它们完全不同),因为在您写入正确的用户名和密码后,身份验证已成功通过,请尝试为您尝试的用户设置适当的权限登录,然后重试。您可以通过在 ASP.NET 的安全/应用程序工具的“授权”选项卡中设置正确的角色,或者通过创建正确的类来手动定义它来做到这一点...如果您处理以下情况,最好还检查 IIS 策略IIS 上的生产代码。如果这不起作用,请发布您编写的身份验证代码。

It seems to be a broblem with the Authorization (dond confuse with Authentication they completely diffrent), becuse the Authentication has been passed successfully after you've written the right user name and password, please try to set the appropriate privilegs to the user you try to login with, then try again. You can do that by set ting the right roles in the Authorization tab in the Security/Application tool of ASP.NET or by defining it manually by creating the right class... You'd better also chack the IIS policy if you deal with production code on IIS. If this is not working please post the Authentication code you've written.

一人独醉 2025-01-15 20:11:21

弄清楚出了什么问题。与授权完全无关,但几天前我愚蠢地编写了代码,当不满足某个条件时抛出 401 错误。删除它证明完成的设置工作完美:)

Figured out what was wrong. Was nothing to do with Authorization at all but I stupidly had written code a few days back throwing a 401 error when a certain condition was not met. Removing that proved that the setup done worked perfectly :)

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