在Azure门户中,我为我的Web应用程序设置了App Service Authentication "On“,并使用AAD作为身份验证提供者。
到目前为止,这很有效,我需要一个允许匿名用户的端点,但是属性[AllowAnonymous]不起作用,我仍然需要登录。
代码:
[Authorize]
[RoutePrefix("users")]
public class UsersController : Controller
{
[Route("register/{skypeid}")]
public ActionResult Register(string skypeid)
{
///stuff...
}
catch (Exception ex)
{
return Content(ex + "");
}
ViewBag.Name = name;
return View();
}
[AllowAnonymous]
[Route("exists/{skypeid}")]
public ActionResult Exists(string skypeid)
{
return Content("Hello " + skypeid);
}我认为代码是正确的,那么它是否与我在Web应用程序中使用App Service Authentication的事实有关?
编辑:所以,我找到了问题的根源,在Azure中,如果你将“未通过身份验证时采取的操作”设置为“使用Azure Active Directory登录”,它永远不允许匿名。
但是,如果我将其更改为允许匿名,则当用户尝试访问具有Authorize-属性的控件时,系统不会提示用户登录,而只是告诉我“您没有查看此目录或页面的权限”。这是故意的吗?看起来真的很奇怪。我希望用户被重定向到登录,如果有一个授权属性。
为了清晰起见,截图:


https://stackoverflow.com/questions/41445189
复制相似问题