在Azure门户内部我设置应用程序服务身份验证“On”对于我的Web应用程序,我使用AAD作为身份验证提供程序。AllowAnonymous属性不工作MVC 5
这直到现在伟大的工作,我需要一个端点,将允许匿名用户,但是属性[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使用App Service身份验证的事实有关?
编辑: 于是,我找到了问题的根源,在Azure中,如果你设置为“未通过身份验证时采取的措施”,以“拍在与Azure中的Active Directory”,但这绝不允许匿名。
但是,如果我将其更改为允许匿名,则在尝试使用[Authorize] -Attribute访问控件时,不会提示用户登录,它只是告诉我“您无权查看此目录或页。” 这是打算?这似乎很奇怪。如果有[Authorize] -Attribute,我希望用户被重定向到登录。
截图的清晰度:
为您的应用程序启用匿名身份验证? https://www.iis.net/configreference/system.webserver/security/authentication/anonymousauthentication –
@ChrisPratt我无法在IIS管理器中看到我的网站,一直这样。无论哪种方式,它都默认启用,除非您可以在Azure Portal中禁用它,否则应该启用它。 –