gpt4 book ai didi

asp.net-mvc - 从 ASP.NET MVC 4 项目中的 WIF 授权中排除特定路径

转载 作者:行者123 更新时间:2023-12-01 19:19:25 25 4
gpt4 key购买 nike

借助 Visual Studio 2012 的身份和访问...扩展,我们已在 ASP.NET 4.5 MVC 4 项目中成功配置了 Windows Identity Foundation (WIF)。但无法从授权中排除特定路径以允许匿名访问。

当我们访问默认路由(即 /Home)时,被动重定向会将我们重定向到配置的颁发者 Uri。这是正确的。但现在假设我们希望从 STS 身份验证中排除路径 /Guest,以便每个人都可以访问 http://ourhost/Guest,而无需路由到 STS 颁发者。那里只有静态文档。

来自 Web.config 的片段:

<system.identityModel>
<identityConfiguration>
<audienceUris>
<add value="http://ourhost/" />
</audienceUris>
<issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<trustedIssuers>
<add thumbprint="9B74****40D0" name="OurSTS" />
</trustedIssuers>
</issuerNameRegistry>
<certificateValidation certificateValidationMode="None" />
</identityConfiguration>
</system.identityModel>
<system.identityModel.services>
<federationConfiguration>
<cookieHandler requireSsl="false" />
<wsFederation passiveRedirectEnabled="true" issuer="http://oursts/Issue" realm="http://ourhost/" reply="http://ourhost/" requireHttps="false" />
</federationConfiguration>
</system.identityModel.services>

此外,我们还有...

<system.webServer>
<!-- ... -->
<modules runAllManagedModulesForAllRequests="true">
<add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
<add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
<remove name="FormsAuthentication" />
</modules>
</system.webServer>

最后:

<system.web>
<!-- ... -->
<authentication mode="None" />
</system.web>

我们尝试了以下方法但没有成功:

<location path="~/Guest"> <!-- also "/Guest" is not working -->
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>

我们还尝试将一个小的 Web.config 文件放入此文件夹中,但没有成功。无论我们在浏览器中找到哪个 Uri,我们总是会被重定向。

实现这一目标的正确方法是什么?

编辑

删除了之前的“接受的答案”,将“接受的答案”设置为 Eugenios answer因为这是更有用的回复。

最佳答案

在 MVC 应用中,您通常通过 Controller 和操作中的 [Authorize] 属性定义访问权限。

只需从 web.config 中删除:

<system.web>
<authorization>
<deny users="?" />
</authorization>

注意:这通常是由 VS2010 中的“添加 STS 引用”向导自动添加的

看起来 VS2012 和新工具上的行为完全相同。我刚刚创建了一个全新的 MVC4 应用程序。使用本地配置 STS 运行“身份和访问...”工具(保留所有默认值)。

它确实将此片段添加到 web.config 中:

<authorization>
<deny users="?" />
</authorization>

我删除了它,并将 [Authorize] 添加到“关于 Controller ”操作:

[Authorize]
public ActionResult About()
{
ViewBag.Message = "Your app description page.";

return View();
}

当我单击“关于”链接时,我会被重定向到 STS。其他一切都可以通过匿名访问进行。

注意:

您也可以在向导中对此进行一些控制(请参阅向导的“配置”页面)。

关于asp.net-mvc - 从 ASP.NET MVC 4 项目中的 WIF 授权中排除特定路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13286844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com