2012-01-06 57 views
9

我在我的locahost上运行MVC3站点时出现此错误。它是新创建的新鲜MVC3网站,HomeControllerIndex方法是从ViewBag.Message分配中抛出的方法。“动态操作只能在同质AppDomain中执行”错误

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

堆栈跟踪:

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) 

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

Microsoft在处理MVC3和MVC2框架之间的安全方面存在一些差异吗?

+1

这个[相关的问题](http://stackoverflow.com/questions/4230909/odd-exception-in-mvc-3-project)可能会揭开一些光线 – PHeiberg 2012-01-06 17:27:41

+0

PHeiberg。感谢您指向我的链接。我的解决方法虽然有点不同。没有在我的web.config中,我明确地设置了''。所以我查看了我的machine.config文件,然后看,那是!我评论说,现在MVC3应用程序运行。谢谢! – 2012-01-06 19:16:54

回答

12

好吧,看来如果你在你的web.config以下行:

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

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

所以我看着machine.config,并有代码行!我评论说,我现在可以运行我的MVC3应用程序。

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

+8

如果您有类似的问题,但在基于Windows窗体的项目,注释此行您的app.config文件: <! - - > David 2012-03-01 17:42:31

+0

我有这个在Forms项目中出现问题......但不幸的是,我无法更改安全策略设置,因为我也使用了POS .NET,如果没有它,它就无法工作。不要以为你有什么想法尝试什么? – Ashley 2013-09-08 01:58:23

+0

@Ashley你有没有想过你能做什么? – skaz 2014-05-18 17:25:29

相关问题