簡體   English   中英

Windows身份驗證MVC 4 Intranet

[英]Windows Authentication MVC 4 Intranet

在mvc 4內部網站點中,當應用程序加載時,如果主頁控制器索引操作,您將如何強制用戶輸入Windows憑據。 似乎瀏覽器正在記住密碼。 如果是這樣,你可以禁止瀏覽器記住嗎?

我正在使用IIS Express。

我允許啟用匿名身份驗證禁用Windows身份驗證,並且主控制器的索引操作具有Authorize屬性。 (現在嘗試控制器級別)

我以為強制輸入憑據。

我正在關注這個http://www.itorian.com/2013/05/windows-authentication-in-mvc4-with-iis.html

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="autoFormsAuthentication" value="false" />
    <add key="enableSimpleMembership" value="false"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="Windows" />
    <authorization>
      <deny users="?" />
    </authorization>
    <identity impersonate="true" />    
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
  <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers></system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

調節器

[Authorize]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

        return View();
    }
    public ActionResult About()
    {
        ViewBag.Message = "Your app description page.";

        return View();
    }

    public ActionResult Contact()
    {
        ViewBag.Message = "Your contact page.";

        return View();
    }
}

這是我猜你沒有提供<appSettings>部分:

指南 (與您提供的鏈接相同)表示您應該設置以下兩個值:

<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>

這是唯一想到的東西,我可以找到指向autoFormsAuthentication更改的每個源。

我發現的另一件事是微軟的指南 這是MVC 3,但我不認為這有任何重大變化。 它比原始教程更長,但它涵蓋了所有設置並解釋了您需要做的所有事情。

當您知道提示出現的原因時,您知道如何打開和關閉它,

http://support.microsoft.com/kb/258063

Internet Explorer必須滿足以下條件才能自動驗證用戶的登錄名和密碼並保持安全性:

  • 必須在IIS的網站屬性中啟用Windows集成身份驗證,也稱為Windows NT質詢/響應。 首先嘗試匿名身份驗證,然后是Windows集成身份驗證,摘要身份驗證(如果適用),最后是基本(明文)身份驗證。
  • 客戶端和Web服務器必須位於相同的基於Microsoft Windows NT或基於Microsoft Windows 2000的域中,或者位於基於受信任Windows NT或基於Windows 2000的域中,在該域中,可以向用戶的帳戶授予對資源的權限基於IIS的計算機。
  • 用戶的瀏覽器必須是Internet Explorer。 Internet Explorer是唯一支持Windows集成身份驗證(NTCR)的瀏覽器。
  • Internet Explorer必須將請求的URL視為Intranet(本地)。 如果請求的URL的計算機名稱部分包含句點(例如 http://www.microsoft.com和10.0.0.1),Internet Explorer假定Internet上存在請求的地址,並且不會自動傳遞任何憑據。 沒有句點的地址(例如網絡服務器)被認為是在內聯網(本地)上; Internet Explorer自動傳遞憑據。 唯一的例外是Internet Explorer中的Intranet區域中包含的地址。
  • Internet Explorer的Intranet區域安全設置必須設置為僅在Intranet區域中自動登錄。 這是Internet Explorer的默認設置。 有關Internet Explorer安全區域的其他信息,請單擊下面的文章編號,以查看Microsoft知識庫中相應的文章:

    174360如何在Internet Explorer中使用安全區域

  • 請求Web頁面的用戶必須具有對Web頁面的適當文件系統(NTFS)權限以及Web頁面中引用的所有對象。 例如,用戶可能對網頁具有完全控制權限,但如果網頁引用安全文件夾中的圖形,則會提示輸入密碼。

如果您故意破壞上述任何一種情況,可以觸發提示。

暫無
暫無

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

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