MVC 4应用程序进入第一个使用Windows身份验证登录页面时运行 [英] MVC 4 application goes to login page first using Windows auth when run
问题描述
我目前正在开发将使用Windows身份验证对用户进行授权并设置其特定权限的项目。然而,我每次运行程序进行测试,当我创建该项目由Visual Studio创建的默认登录页面(/帐号/登录)总是先出现,而不是去首页/索引。网址通常的http://本地主机:50848 /帐号/登录RETURNURL =%2fViews%2fHome%2fIndex.cshtml
当我启动它,而不仅仅是的http://本地主机:50848
。我还要指出,该方案越来越屏幕上正确的Windows身份验证,所以我知道那部分工作。
I am currently developing a project that will use Windows authentication to authorize users and set their specific permissions. However, every time I run the program to test, the default login page created by Visual Studio when I created the project (/Account/Login) always appears first, rather than going to Home/Index. The URL is usually http://localhost:50848/Account/Login?ReturnUrl=%2fViews%2fHome%2fIndex.cshtml
when I start it up, rather than just http://localhost:50848
. I should also note that the program is getting the correct Windows authentication on the screen, so I know that part is working.
有东西在我的设置,我可以改变,以阻止弹出这些额外的登录屏幕?我使用Visual Studio 2012中,IIS防爆preSS和MVC 4.有关code:
Is there something in my settings I can change to stop this extra login screen from popping up? I am using Visual Studio 2012, IIS Express , and MVC 4. Relevant code:
Web.config文件
Web.config
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="false" />
<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="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>-->
<authentication mode="Windows"/>
<authorization>
<deny users="?"/>
</authorization>
<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="true" />
<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>
IIS防爆preSS对ApplicationHost.config
IIS Express 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>
是的,我已经改变了Windows身份验证为Enabled和匿名身份验证禁用。
And yes, I have changed Windows Authentication to 'enabled' and Anonymous Authentication to 'disabled'.
推荐答案
事实证明,创建ASP.NET MVC应用程序时,会生成两个Web.config文件中。我的变化进入了错误的web.config文件(视图文件夹下的一个),而不是主要的一个应用程序。通过应用在我原来的问题更改这个其他的配置文件,应用程序按预期工作。
As it turns out, when creating an MVC ASP.NET application, two web.config files are generated. My changes were going into the wrong web.config file (the one under the views folder), rather than the main one in the application. By applying the changes in my original question to this other config file, the application works as intended.
有关这两个web.config文件中的详细信息,请参阅本SO问题:<一href=\"http://stackoverflow.com/questions/23509617/why-net-generate-two-web-config-files-in-mvc-asp-net-application\">Why .NET生成MVC asp.net适用的两个web.config文件中?
For more information on the two web.config files, see this SO question: Why .NET generate two web.config files in MVC asp.net application?
这篇关于MVC 4应用程序进入第一个使用Windows身份验证登录页面时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!