我如何在MVC5中实现异常过滤器.
我想将异常抛给NLog并将页面重定向到默认错误页面,显示"出错了"
我有一个Filter类如下
using System;
using System.Diagnostics;
using System.Security.Policy;
using System.Web.Mvc;
using System.Web.Mvc.Filters;
using System.Web.Routing;
using System.Web.UI.WebControls;
using Delivros.UI.Controllers;
using Delivros.UI.Areas.User.ViewModel;
using System.Web;
namespace Delivros.UI.Filters
{
public class CustomAuthenticationFilter : IAuthenticationFilter
{
public void OnAuthentication(AuthenticationContext filterContext)
{
}
public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
{
Debug.WriteLine("OnAuthenticationChallenge : MyAuthenticationFilter");
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MyAuthorizationFilter : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (filterContext.RequestContext.HttpContext.Request.Cookies[System.Configuration.ConfigurationManager.AppSettings[Convert.ToString(CookieField.cookieName)]] == null)
{
}
else
{
filterContext.Result = new …Run Code Online (Sandbox Code Playgroud) 我正在使用资源文件在我的Web应用程序中切换语言,该应用程序是在mvc5中构建的
在索引文件中,它读取我设置的文化值.
我从layout.cshtml调用set culture方法并使用以下代码调用其值.
@{
Layout = "~/Views/Shared/_Layout.cshtml";
if (!Request["dropdown"].IsEmpty())
{
Culture = UICulture = Request["dropdown"];
}
Run Code Online (Sandbox Code Playgroud)
}
在索引页面中语言正确加载,但是当我从那里进入下一页时,它加载默认语言德语,但资源仅从英语资源文件中读取.
请帮帮我..这个人