“Dynamic operations can only be performed in homog

2020-08-27 05:12发布

问题:

I'm getting this error when running an MVC3 site on my locahost. It is a fresh MVC3 site just newly created, the HomeController Index method is where it's being thrown from, on the ViewBag.Message assignment.

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

Stack trace:

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)

I have no idea what this error is and haven't seen it before. When I start up a new MVC2 project (what I've been using up until this point), the site runs just fine.

Is there some difference in how Microsoft treats security between the MVC3 and MVC2 frameworks?

回答1:

Okay, it seems that if you have the following line in your web.config:

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

this type of error could happen. Yet in the link that PHeiberg provided to me, it said the line could be in web.config. My web.config did not have it.

So I looked in machine.config, and there was the code line! I commented it out, and I can now run my MVC3 app.

I'm not too sure how it ended up in machine.config, or what else I might have broken as a result of me commenting it out, but this immediate problem is fixed.