I would like to secure whole website so that every page except login page would require a user to be authenticated. In order to achieve this, I register Authorize
filter at application startup:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new AuthorizeAttribute());
}
Now there is a problem with my LoginController
, which despite applying [AllowAnonymous]
attribute to it and still requires user to be authenticated. This is my login controller:
[AllowAnonymous]
public class LoginController : SurfaceController
{
public LoginController()
{
}
[HttpPost]
[ValidateAntiForgeryToken]
[AllowAnonymous]
public async Task<ActionResult> HandleLogin(LoginModel model, string returnTo)
{
return CurrentUmbracoPage();
}
}
There are no other child actions on the page and the problem is definitively with the LoginController
. What happens here and how it can be fixed?
UPDATE: my views are
Login page template:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
// Layout = "Master.cshtml";
Layout = null;
}
<div>@Umbraco.Field("bodyText")</div>
@Html.Partial("Login")
Login Partial is:
@using ClientDependency.Core.Mvc
@using PlayProj.Presentation.Controllers
@using Umbraco.Web
@using Umbraco.Web.Models
@{
var loginModel = new LoginModel();
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
Html
.RequiresJs("~/scripts/jquery.validate.hooks.js", 200)
.RequiresJs("~/scripts/foundation.form.validation.js", 201);
}
@using (Html.BeginUmbracoForm<LoginController>("HandleLogin", null, new { @class = "loginForm", autocomplete = "off" }))
{
<fieldset>
<legend>Login</legend>
<button>Login</button>
</fieldset>
}