【问题标题】:WIF correlation with AuthorizeAttribute in MVC for access restriction to certain pagesWIF 与 MVC 中的 AuthorizeAttribute 相关,用于限制对某些页面的访问
【发布时间】:2012-08-17 02:53:18
【问题描述】:

在我的 MVC 应用程序中,我使用的是 WIF。我使用 Visual Studio 内置工具添加了 STS 参考。 FedUtil 在 web.config 中生成了一些条目:

<microsoft.identityModel>
    <service>
      <claimsAuthenticationManager type="Social.Core.Security.RolesAwareClaimsAuthenticationManager, Social.Core" />
      <audienceUris>
        <add value="http://app.something.com/" />
      </audienceUris>
...

如您所见,另外我还编写了自定义 ClaimsAuthenticationManager 来为已从 STS 收到的声明添加一些声明。

但是,在应用程序中我有限制页面:

public class ProfileController : BaseController
{
    [Authorize]
    public virtual ActionResult Index()
    {
        // restricted area
    }
}

我已在受限操作中添加了 AuthorizeAttribute。我只需要在输入 app.something.com/profile/index 时进行身份验证。不幸的是,现在登录表单会在进入应用程序的任何部分时显示,例如主页 app.something.com

如何将 WIF 身份验证与 AuthorizeAttribute 关联起来,只授权我需要的东西?也许我需要在 web.config 或 STS 中的某处添加 app.something.com/profile/index ?有什么线索吗?

【问题讨论】:

  • 您确定是[Authorize] 属性导致了问题吗?删除它会出现问题吗?
  • 我不知道你是否清楚我在问什么。也许我的问题不清楚。我想让它使用这个属性(使用这个属性访问操作时由 WIF 提供的触发登录表单)或者至少限制对特定页面的访问 - 而不是整个站点,没有这个属性的任何其他方式。
  • 我暗示该特定属性不会导致您的主页需要身份验证。像 woloski 建议的那样,有别的东西在做这件事

标签: asp.net asp.net-mvc asp.net-mvc-3 wif


【解决方案1】:

当您运行添加 STS 引用时,向导将添加授权部分并拒绝匿名用户。删除它。

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

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 2022-11-26
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 2020-12-01
    相关资源
    最近更新 更多