2014-04-28 111 views
0

在mvc 4內聯網站點中,當應用程序載入主控制器索引操作時,您將如何強制用戶輸入Windows憑據。好像瀏覽器正在記住密碼。如果是這樣,你可以禁止瀏覽器記住?Windows身份驗證MVC 4內聯網

我正在使用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(); 
    } 
} 
+0

第一件事:你爲什麼要將你的源文件發佈爲圖片?爲避免在測試時記住密碼,請嘗試使用隱身模式。爲了避免在部署版本中出現這種情況,您可能會將登錄cookie保存爲會話,這意味着在用戶關閉Web瀏覽器後它會被刪除。我從來沒有嘗試過在asp.net中,我只知道PHP的概念。 –

+0

更新了代碼,但它不會提示我輸入它們,它只是正確登錄我。 – user1307149

+0

它至少使用正確的憑據,因此您登錄的用戶訪問該頁面,或它不'完全限制訪問? –

回答

1

這是因爲你沒有提供<appSettings>部分我只是猜測:

guide(這是同一個鏈接你已經提供)說你應該設置這兩個值:

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

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

我發現的另一件事是Microsoft's guide。這是MVC 3,但我沒有任何關於這方面的重大變化。它比您的原始教程長,但涵蓋了所有設置並解釋了您需要做的所有事情。

+0

這就是我所看到的,並轉發了上述配置文件 – user1307149

+0

@ user1307149,我已經更新了答案,請查看它並讓我知道它是如何發生的。 –

+0

會生病給我一個鏡頭,這是我沒有找到的。謝謝。 – user1307149

1

當你知道爲什麼會出現提示,你知道如何打開和關閉它,

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

下列條件必須滿足的Internet Explorer,以 自動驗證用戶登錄和密碼和維護 安全性:

  • Windows集成身份驗證,也稱爲Windows N T 質詢/響應,必須在IIS的網站屬性中啓用。 首先嚐試匿名身份驗證,然後是Windows 集成身份驗證,摘要式身份驗證(如果適用)和 最終基本(明文)身份驗證。
  • 客戶端和Web 服務器必須位於相同的基於Microsoft Windows NT或基於Microsoft Windows 2000的域中,或位於基於Windows NT的受信任域或基於Windows 2000的域中,其中用戶的帳戶可以位於基於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上,並且 不會自動傳遞任何憑據。無週期的地址(如 網絡服務器)被認爲是在Intranet(本地)上; Internet Explorer自動傳遞憑據。唯一的例外是 是包含在Internet Explorer中的Intranet區域中的地址。
  • Internet Explorer的Intranet區域安全設置必須設置爲 僅在Intranet區域中自動登錄。這是 Internet Explorer的默認設置。有關Internet Explorer 安全區域的其他信息,請單擊文章編號下面以查看在文章中 Microsoft知識庫:

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

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

如果您有意打破上述任何條件,就可以觸發提示。