簡體   English   中英

在ASP.NET中使用Windows身份驗證

[英]Using Windows Authentication in ASP.NET

我正在嘗試在我的ASP.NET應用程序中使用Windows身份驗證。 每當我嘗試查看應用程序時,它都會將我發送到登錄頁面。 如何在不通過瀏覽器手動登錄的情況下使其工作?

web.config中

  <system.web>
    <authentication mode="Windows"></authentication>
    <anonymousIdentification enabled="false"/>
    <authorization>
      <deny users="?" />
      <allow users="*" />
    </authorization>
    <customErrors mode="Off"></customErrors>
    <identity impersonate="true"></identity>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime />
  </system.web>

更新IIS Express后出錯

Most likely causes:
No authentication protocol (including anonymous) is selected in IIS.
Only integrated authentication is enabled, and a client browser was used that does not support integrated authentication.
Integrated authentication is enabled and the request was sent through a proxy that changed the authentication headers before they reach the Web server.
The Web server is not configured for anonymous access and a required authorization header was not received.
The "configuration/system.webServer/authorization" configuration section may be explicitly denying the user access.

對ApplicationHost.config

<authentication>
  <anonymousAuthentication enabled="false" />
  <basicAuthentication enabled="false" />
  <clientCertificateMappingAuthentication enabled="false" />
  <digestAuthentication enabled="false" />
  <iisClientCertificateMappingAuthentication enabled="false">
  </iisClientCertificateMappingAuthentication>

  <windowsAuthentication enabled="true">
    <providers>
      <add value="Negotiate" />
      <add value="NTLM" />
    </providers>
  </windowsAuthentication>
</authentication>

使用IISExpress進行Windows身份驗證

更新您的web.config

確保您的web.config文件都啟用了Windows身份驗證,並且還拒絕匿名身份驗證。 如果應用程序通過匿名身份驗證, HttpContext.Current.User.Identity.Name將為空。 您的配置應如下所示:

<authentication mode="Windows" />
<authorization>
    <deny users="?"/>
</authorization>

錯誤401.2未經授權有時,您可能會收到錯誤401.2 Unauthorized: Logon failed due to server configuration error 如果這樣做,請驗證您是否有權根據您提供的憑據查看此目錄或頁面。 還要確保在Web服務器上啟用了身份驗證方法。

更新applicationhost.config

您還可能會發現必須更新IISExpress applicationhost.config文件(不要擔心 - 我也不知道)。 這基本上是IIS配置工具的文件版本,您可以在其中配置Web服務器本身。 查找applicationhost.config文件可能很棘手。 它可能在:

%userprofile%\\documents\\iisexpress\\config\\applicationhost.config

要么

%userprofile%\\my documents\\iisexpress\\config\\applicationhost.config

找到后,更新以下行(特別注意enabled=true ):

<windowsAuthentication enabled="true">
    <providers>
        <add value="Negotiate" />
        <add value="NTLM" />
    </providers>
</windowsAuthentication>

這是文章

我們對幾乎所有的Intranet應用程序(包括SharePoint)都使用Windows身份驗證。 如果員工的瀏覽器未自動將其Windows憑據自動發送到站點,則員工必須登錄。

在IE上,這是瀏覽器配置的問題。 我認為還有一些方法可以配置Chrome和Firefox自動發送Windows登錄。 我認為Chrome會像IE一樣關注Window的互聯網設置(在客戶端上)。 嘗試將用戶身份驗證選項設置為“使用當前用戶名和密碼自動登錄”。

請參閱下面的屏幕截圖,了解其位置。

在此輸入圖像描述

另請注意,這涉及用戶的瀏覽器將Windows令牌發送到應用程序。 應用程序必須理解並信任此令牌的來源,這可以在用戶和應用程序所在的“域”的支持下工作。我認為它可以在單個機器上工作(在調試時),但是如果您希望這在網絡上的多台計算機上運行,​​則需要考慮創建域。 創建域的典型方法是Active Directory。

讓我知道。

在VS 2017中調試我的Web應用程序時,我發現需要更新[解決方案路徑] \\。vs \\ config \\ applicationhost.config。 我將身份驗證部分替換為:

        <authentication>
          <anonymousAuthentication enabled="false" userName="" />

          <basicAuthentication enabled="false" />

          <clientCertificateMappingAuthentication enabled="false" />

          <digestAuthentication enabled="false" />

          <iisClientCertificateMappingAuthentication enabled="false">
          </iisClientCertificateMappingAuthentication>

          <windowsAuthentication enabled="true">
            <providers>
              <add value="Negotiate" />
              <add value="NTLM" />
            </providers>
          </windowsAuthentication>

        </authentication> 

更多信息: https//stackoverflow.com/a/4813716/555142

  1. 打開IIS(Windows + R'inettr')
  2. 選擇IIS服務器(根節點)
  3. 雙擊 - '身份驗證'
  4. Windows身份驗證 - 右鍵單擊​​並選擇“啟用”
  5. 表單身份驗證 - 右鍵單擊​​並選擇“禁用”
  6. 重新啟動IIS服務器

通過刪除協商提供程序,我能夠讓它工作。

  <windowsAuthentication enabled="true">
    <providers>
      <add value="NTLM" />
    </providers>
  </windowsAuthentication>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM