Asp.net mvc 4 为什么赢了';这不是我的MVC4手稿吗?
我正在将一个MVC3 web项目转换为MVC4。我创建了一个ElmahHandleErrorAttribute,它继承了HandleErrorAttribute,该属性在MVC3中运行良好,在本地开发人员机器上也运行良好,但在测试环境中会引发以下异常Asp.net mvc 4 为什么赢了';这不是我的MVC4手稿吗?,asp.net-mvc-4,Asp.net Mvc 4,我正在将一个MVC3 web项目转换为MVC4。我创建了一个ElmahHandleErrorAttribute,它继承了HandleErrorAttribute,该属性在MVC3中运行良好,在本地开发人员机器上也运行良好,但在测试环境中会引发以下异常 [InvalidOperationException: The given filter instance must implement one or more of the following filter interfaces: IAuthor
[InvalidOperationException: The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
System.Web.Mvc.GlobalFilterCollection.ValidateFilterInstance(Object instance) +110
System.Web.Mvc.GlobalFilterCollection.AddInternal(Object filter, Nullable`1 order) +17
System.Web.Mvc.GlobalFilterCollection.Add(Object filter) +12
Home2Me.MvcApplication.RegisterGlobalFilters(GlobalFilterCollection filters) in c:\###\Home2Me\Global.asax.cs:16
Home2Me.MvcApplication.Application_Start() in c:\###\Home2Me\Global.asax.cs:118
[HttpException (0x80004005): The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9249709
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9164336
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
这门课真的没有什么特别之处。这与Elmah的标准版本非常接近
public class ElmahHandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute
{
/// <summary>
/// Called when an exception occurs.
/// </summary>
/// <param name="context"></param>
public override void OnException(ExceptionContext context)
{
base.OnException(context);
if (!context.ExceptionHandled) return; // if unhandled, will be logged anyhow
var e = context.Exception;
HandleException(e);
}
... (code snipped for brevity) ...
}
过滤器在一个单独的程序集中定义,该程序集也更新为MVC4。我有多个使用此筛选器的项目。其中一个可以在测试环境中正常工作,另一个也有同样的问题
有什么想法可能是错误的吗?我确信项目中的所有MVC3引用都已正确更新,包括根目录和视图目录中的web.config文件。它在本地工作,我卸载了MVC3并删除了所有“额外”的MVC3 DLL 我相信我找到了答案。我在根web.config文件中添加了一个运行时部分,以将MVC3引用转换为MVC4
<configuration>
... (snipped for brevity) ...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
... (为了简洁起见被剪掉了)。。。
我宁愿修复引用MVC3的任何内容,但我不知道这可能是什么。这将是一个足够好的答案
<configuration>
... (snipped for brevity) ...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>