Windows 身份验证 MVC - 1 IIS_Express 服务器、2 个应用程序、2 个结果
Windows Authentication MVC - 1 IIS_Express server, 2 Apps, 2 Results
大家好
我完全被难住了。我正在使用 MS VSExpress 2013 for Web 开发 MVC 应用程序,现在我需要添加 Windows 身份验证。使用向导创建默认 MVC 应用程序并选择 Windows 身份验证,它似乎工作正常。让我们调用默认应用程序App1,我开发的应用程序App2。
在两个应用程序的 Watch 中监控 Context.User 对象:
App1 returns:
User {System.Security.Principal.WindowsPrincipal}
System.Security.Principal.WindowsIdentity
AuthenticationType "Negotiate" string
IsAuthenticated true bool
Name "MyDomain\Andrew" string
使用开发的app时,结果如下: 请注意,返回的对象不同(App1 = System.Security.Principle.WindowsPrinciple, App2 = System.Web.Security.RolePrinciple.
User {System.Web.Security.RolePrincipal}
Identity {System.Security.Principal.GenericIdentity}
AuthenticationType "" string
IsAuthenticated false bool
Name "" string
HttpContext.Current.Request.LogonUserIdentity.Name "MyDomain\Andrew"
将开发的应用程序开发服务器属性切换为Windows身份验证=启用,匿名身份验证=禁用时,结果立即:
Server Error in "/" Application.
Resource cannot be found.
Http 404...
Requested URL:/Account/Login
我检查并比较了:
Web.config 个文件和 IISExpress\config\applicationhost.config 两个应用程序的设置。
我的知识有限(基于阅读我能找到的关于 SO 的所有问题),我猜 App2 认为它使用的是表单身份验证,而不是 Windows 身份验证。 App2 正在通过
获取用户信息
HttpContext.Current.Request.LogonUserIdentity.Name 对象(在 SO 上找到)。
我添加了:
<add key="autoFormsAuthentication" value="false" />
到Web.config ...没有快乐。
任何人都知道为什么这两个应用程序返回不同的用户对象,在哪里可以更正?为什么 App2 无法从与 App1 相同的 IISExpress 服务器获取 IsAuthenticated=true?
谢谢
http://www.itorian.com/2013/05/windows-authentication-in-mvc4-with-iis.html
由于一些奇怪的原因(EDIT 这是原因-> ASP.NET MVC3 and Windows Auth on IIS keeps redirecting to /Account/Login /EDIT ,向导生成的 app1 没有Web.config
内不需要这两行
<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>
添加第 2 行后,返回的 Context User 对象从
System.Security.Principal.GenericIdentity
到
System.Security.Principal.WindowsPrincipal
一切都很好。
还要确保您的 IISExpress 服务器配置文件 applicationhost.config(在 IISExpress 安装文件夹中)包含所需的正确条目:
全球条目:
<windowsAuthentication enabled="true">
<providers>
<add value="Negotiate" />
<add value="NTLM" />
</providers>
</windowsAuthentication>
大家好 我完全被难住了。我正在使用 MS VSExpress 2013 for Web 开发 MVC 应用程序,现在我需要添加 Windows 身份验证。使用向导创建默认 MVC 应用程序并选择 Windows 身份验证,它似乎工作正常。让我们调用默认应用程序App1,我开发的应用程序App2。
在两个应用程序的 Watch 中监控 Context.User 对象:
App1 returns:
User {System.Security.Principal.WindowsPrincipal}
System.Security.Principal.WindowsIdentity
AuthenticationType "Negotiate" string
IsAuthenticated true bool
Name "MyDomain\Andrew" string
使用开发的app时,结果如下: 请注意,返回的对象不同(App1 = System.Security.Principle.WindowsPrinciple, App2 = System.Web.Security.RolePrinciple.
User {System.Web.Security.RolePrincipal}
Identity {System.Security.Principal.GenericIdentity}
AuthenticationType "" string
IsAuthenticated false bool
Name "" string
HttpContext.Current.Request.LogonUserIdentity.Name "MyDomain\Andrew"
将开发的应用程序开发服务器属性切换为Windows身份验证=启用,匿名身份验证=禁用时,结果立即:
Server Error in "/" Application.
Resource cannot be found.
Http 404...
Requested URL:/Account/Login
我检查并比较了: Web.config 个文件和 IISExpress\config\applicationhost.config 两个应用程序的设置。
我的知识有限(基于阅读我能找到的关于 SO 的所有问题),我猜 App2 认为它使用的是表单身份验证,而不是 Windows 身份验证。 App2 正在通过
获取用户信息HttpContext.Current.Request.LogonUserIdentity.Name 对象(在 SO 上找到)。
我添加了:
<add key="autoFormsAuthentication" value="false" />
到Web.config ...没有快乐。
任何人都知道为什么这两个应用程序返回不同的用户对象,在哪里可以更正?为什么 App2 无法从与 App1 相同的 IISExpress 服务器获取 IsAuthenticated=true?
谢谢
http://www.itorian.com/2013/05/windows-authentication-in-mvc4-with-iis.html
由于一些奇怪的原因(EDIT 这是原因-> ASP.NET MVC3 and Windows Auth on IIS keeps redirecting to /Account/Login /EDIT ,向导生成的 app1 没有Web.config
内不需要这两行<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>
添加第 2 行后,返回的 Context User 对象从
System.Security.Principal.GenericIdentity
到
System.Security.Principal.WindowsPrincipal
一切都很好。 还要确保您的 IISExpress 服务器配置文件 applicationhost.config(在 IISExpress 安装文件夹中)包含所需的正确条目: 全球条目:
<windowsAuthentication enabled="true">
<providers>
<add value="Negotiate" />
<add value="NTLM" />
</providers>
</windowsAuthentication>