"动态操作只能在同类AppDomain中执行"错误

Mic*_*thy 9 asp.net asp.net-mvc-3 asp.net-mvc-2

我在locahost上运行MVC3站点时遇到此错误.它是一个刚刚创建的新MVC3站点,该HomeController Index方法是在ViewBag.Message作业中被抛出的地方.

public ActionResult Index()
{
    ViewBag.Message = "Welcome to ASP.NET MVC!";
    return View();
}
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at MVC3.Web.UI.Controllers.HomeController.Index() in C:\Users\mccarthy\Documents\Visual Studio 2010\Projects\MVC3\MVC3.Web.UI\Controllers\HomeController.cs:line 13
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
Run Code Online (Sandbox Code Playgroud)

我不知道这个错误是什么,以前没见过.当我启动一个新的MVC2项目(直到这一点我一直在使用)时,该网站运行得很好.

Microsoft如何处理MVC3和MVC2框架之间的安全性有什么不同?

Mic*_*thy 13

好的,似乎如果你的web.config中有以下行:

<trust legacyCasModel="true" level="Full" />

这种错误可能会发生.然而在PHeiberg提供给我的链接中,它表示该行可以在web.config中.我的web.config没有它.

所以我查看了machine.config,并且有代码行!我评论了它,现在我可以运行我的MVC3应用程序了.

我不太确定它是如何在machine.config中结束的,或者我可能因为我评论它而破坏了什么,但这个直接的问题是固定的.

  • 如果您在基于Windows窗体的项目中遇到类似问题,请在app.config文件中注释此行:<runtime> <! - <NetFx40_LegacySecurityPolicy enabled ="true"/> - > </ runtime> (9认同)