我想要得到一個ASP.NET MVC應用程序工作...我應該知道這並不容易。前幾頁工作,但它們都是靜態的。第一次執行一個控制器時,我會得到下面的例外。ASP.NET MVC應用程序有SecurityException
這裏是控制器的操作方法:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Index(Section? section, int? parent)
{
if (section == null)
{
return RedirectToAction("Index", "Questions", new {section = Section.Section0});
}
IPagedList<Question> questions = _surveyService.FetchQuestions(User.Identity.Name, section.Value, parent);
// ...
ViewResult result = View("Index", questions);
result.ViewData.Add("CurrentSection", section.Value);
result.ViewData.Add("Parent", parent);
result.ViewData.Add("IsLastPage", questions.IsLastPage);
return result;
}
該異常是在RedirectToAction()
拋出的方法中的第二行。
背景:
- 我跟着this answer的說明。
- 我沒有在代碼中明確使用反射或要求安全。
- 我使用MVC,的LINQ to SQL,Elmah和PagedList。
- 我正在使用IIS 7與 集成模式。
- 我加入[組件: AllowPartiallyTrustedCallers]到我 AssemblyInfo.cs中。我這樣做是因爲我發現另一個堆棧溢出問題,它有一個建議它的答案(我現在找不到它,否則我會提供一個鏈接)。我也強烈地按照Rex M的回答下面的建議命名我的程序集。
我缺少什麼,使這項工作?
例外:
Server Error in '/surveys/objectification' Application.
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SecurityException: That assembly does not allow partially trusted callers.]
SelfObjectificationSurvey.Web.Controllers.QuestionsController.Index(Nullable`1 section, Nullable`1 parent) +0
lambda_method(ExecutionScope , ControllerBase , Object[]) +123
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7()
+53
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9()
+20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
+382
System.Web.Mvc.Controller.ExecuteCore()
+123
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +144
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
+75
Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.4049
我很好奇,一個接受答案的7歲老人的問題是如何得到解決的? – jrummell 2016-08-21 16:49:54