Ho implementato la gestione degli errori nel sito ASP.NET MVC in a way like suggests this post.ASP.NET MVC user-friendly 401 error
Con 404 errori tutto funziona correttamente. Ma come visualizzare correttamente la schermata user friendly per un errore ? Solitamente non generano eccezioni che possono essere gestite all'interno di Application_Error()
, ma l'azione restituisce HttpUnauthorizedResult. Un modo possibile è aggiungere seguente codice alla fine del metodo Application_EndRequest()
if (Context.Response.StatusCode == 401)
{
throw new HttpException(401, "You are not authorised");
// or UserFriendlyErrorRedirect(new HttpException(401, "You are not authorised")), witout exception
}
Ma dentro Application_EndRequest()
Context.Session == null, errorController.Execute()
riesce perché non è possibile utilizzare TempDataProvider predefinito.
// Call target Controller and pass the routeData.
IController errorController = new ErrorController();
errorController.Execute(new RequestContext(
new HttpContextWrapper(Context), routeData)); // Additional information: The SessionStateTempDataProvider requires SessionState to be enabled.
Quindi, puoi suggerire alcune best practice su come "gestire l'utente '401 nell'applicazione ASP.NET MVC?
Grazie.
http://stackoverflow.com/questions/2580596/how-do-you-handle-ajax-requests -quando-utente-non-autenticato/2595436 # 2595436 – Cherian