在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中禁用它,否則應該啓用它。 –