WIF与MVC中的AuthorizeAttribute相关联,以限制对某些页面的访问

时间:2012-08-16 09:30:48

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

在我的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?有线索吗?

1 个答案:

答案 0 :(得分:2)

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

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