Такое поведение в MVC3 или MVC4 является таким же разработанным, однако оно очень недружелюбен пользователю, как описано выше, однако в производстве эта проблема должна быть решена изящно, и приложение должно справиться с этой странной ситуацией. Решение этой проблемы заключается в создании фильтра, который применяется к сообщению входа, который проверяет, был ли пользователь зарегистрирован и отобрал их на правильной странице, иначе они останутся на странице входа.
Ниже приведен код для фильтра атрибутов
/// <summary>
/// Handle Antiforgery token exception and redirect to customer area if the user is Authenticated
/// </summary>
public class RedirectOnError : HandleErrorAttribute
{
/// <summary>
/// Override the on exception method and check if the user is authenticated and redirect the user
/// to the customer service index otherwise continue with the base implamentation
/// </summary>
/// <param name="filterContext">Current Exception Context of the request</param>
public override void OnException(ExceptionContext filterContext)
{
if (filterContext.Exception is HttpAntiForgeryException && filterContext.HttpContext.User.Identity.IsAuthenticated)
{
// Set response code back to normal
filterContext.HttpContext.Response.StatusCode = 200;
// Handle the exception
filterContext.ExceptionHandled = true;
UrlHelper urlH = new UrlHelper(filterContext.HttpContext.Request.RequestContext);
// Create a new request context
RequestContext rc = new RequestContext(filterContext.HttpContext, filterContext.RouteData);
// Create a new return url
string url = RouteTable.Routes.GetVirtualPath(rc, new RouteValueDictionary(new { Controller = "CustomerArea", action = "Index" })).VirtualPath;
// Check if there is a request url
if (filterContext.HttpContext.Request.Params["ReturnUrl"] != null && urlH.IsLocalUrl(filterContext.HttpContext.Request.Params["ReturnUrl"]))
{
url = filterContext.HttpContext.Request.Params["ReturnUrl"];
}
// Redirect the user back to the customer service index page
filterContext.HttpContext.Response.Redirect(url, true);
}
else
{
// Continue to the base
base.OnException(filterContext);
}
}
}
Это пример использования
[HttpPost]
**[RedirectOnError]**
[ValidateAntiForgeryToken]
public ActionResult LogOn(LogOnViewModel model, UserSessionState session, string returnUrl)
{
.....
}
Я оставил вам еще один ответ - я ответил на свой вопрос! –