【发布时间】:2016-04-28 18:26:21
【问题描述】:
我在使用 .Net MVC 5 应用程序配置 ADFS 时遇到问题。
我已在 VS 2015 中将我的项目配置为使用声明,它工作正常,但我有一个问题。
我可以登录,使用 ADFS,我可以检查用户角色等。当我尝试使用时出现问题
[Authorize(Roles="somenonExistingRole")]
尽管我已经通过身份验证,但当再次进行身份验证时,我被重定向到 ADFS 页面,并且我被重定向到发生循环的页面。页面将我发送到 ADFS 门户,ADFS 将我重定向到门户,经过几次尝试后,我从 ADFS 收到错误(对许多请求)
我必须自己实现角色提供者之类的东西吗?或者我需要配置一些额外的东西。也许我可以限制尝试次数?为什么我已经准备好角色后会重定向到 ADFS?
在代码中实际上并没有太多可显示的内容,而是按要求显示: 我正在测试的控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[Authorize]
public ActionResult About()
{
var u = HttpContext.User;
if (u.IsInRole("/"))
{
ViewBag.Message = "User is in role.";
}
else
{
ViewBag.Message = "User is NOT in role.";
}
return View();
}
[Authorize(Roles = "/nonexistingRole")]
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
和配置身份验证部分
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata,
});
}
【问题讨论】:
-
你的 AuthenticateAttribute 是什么?你能告诉我们代码吗
-
sory - 凭记忆写 授权offcourse :)
-
你有配置 authent 的 Startup.Auth 类吗?
-
你的意思是部分类 Startup 和 ConfigureAuth 功能?如上图
-
您能否更新帖子的标题以进一步解释您的问题,例如:Redirect loop with .Net MVC Authorize attribute with ADFS Claims?欢呼
标签: .net asp.net-mvc claims-based-identity adfs claims