简体   繁体   English

asp.net中的windows身份验证

[英]windows authentication in asp.net

In Asp.net Application for windows authentication在 Windows 身份验证的 Asp.net 应用程序中

In aspx page在aspx页面

asp:Label runat="server" ID="windows"  

aspx.cs page aspx.cs 页面

windows.Text = User.Identity.Name;

webconfig:网络配置:

authentication mode="Windows"

but authentication is not performed what problem ??但是没有进行身份验证是什么问题??

Add the following in your web.config under system.web to make sure that the windows authorization is triggered:在 system.web 下的 web.config 中添加以下内容以确保触发 Windows 授权:

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

Because Integrated Windows Authentication uses the current Windows user information on the client computer for the authentication, it does not immediately prompt the user for a user name and password .由于集成 Windows 身份验证使用客户端计算机上的当前 Windows 用户信息进行身份验证,因此它不会立即提示用户输入用户名和密码 However, if the authentication exchange cannot identify the user, a dialog box appears that prompts the user for a Windows user account user name and password但是,如果身份验证交换无法识别用户,则会出现一个对话框,提示用户输入 Windows 用户帐户用户名和密码

Source: How to implement Windows authentication and authorization in ASP.NET来源:如何在 ASP.NET 中实现 Windows 身份验证和授权

Try adding the following block to see if it's working尝试添加以下块以查看它是否有效

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

After adding this, run the application and you should get HTTP 401 - Access is denied error .添加后,运行应用程序,您应该得到HTTP 401 - Access is denied 错误

You can customize authorization from then on.从此您可以自定义授权。

UPDATE:更新:

Here's a different approach and how to configure it via IIS management console:这是一种不同的方法以及如何通过 IIS 管理控制台对其进行配置:

  1. Deploy your site to IIS将您的站点部署到 IIS
  2. Click on your site and select Authentication单击您的站点并选择身份验证
  3. Disable Anonymous Authentication and enable Windows Authentication as shown in the image below禁用匿名身份验证并启用 Windows 身份验证,如下图所示

在此处输入图片说明

  1. Go back to features and select .NET Authorization Rules .返回功能并选择.NET Authorization Rules Here you can add allow/deny rules on a role or user basis.您可以在此处基于角色或用户添加允许/拒绝规则。

在此处输入图片说明

To test your current code deny anonymous users and allow all.要测试您当前的代码,拒绝匿名用户并允许所有用户。 When you connect to your application you should be able to use the Windows user you used to log in.当您连接到您的应用程序时,您应该能够使用您用于登录的 Windows 用户。

Your web.config wants to contain like this:你的web.config想要包含这样的:

<configuration>
  <system.web>
    <authentication mode="Windows" />
    <anonymousIdentification enabled="false" />
    <authorization>
      <deny users="?" />
    </authorization>
  </system.web>
</configuration>

This will force all users to use their windows/Active Directory login.这将强制所有用户使用他们的 windows/Active Directory 登录。 A 401 Access Denied error will be given to those who don't log in.未登录的用户将收到 401 Access Denied 错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM