【问题标题】:Security Exception for default MVC 5 application默认 MVC 5 应用程序的安全异常
【发布时间】:2014-11-29 07:18:23
【问题描述】:

将使用 VS 2013 生成的默认 MVC 5 应用程序部署到我的主机帐户时出现安全异常。

这个问题有什么快速的解决方法吗?

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: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   Microsoft.Owin.Host.SystemWeb.Infrastructure.DefaultTraceFactory.InitializeTraceSource(String key) +0
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72
   Microsoft.Owin.Host.SystemWeb.Infrastructure.DefaultTraceFactory.GetOrAddTraceSource(String name) +52
   Microsoft.Owin.Host.SystemWeb.Infrastructure.DefaultTraceFactory.Create(String name) +28
   Microsoft.Owin.Host.SystemWeb.OwinAppContext..ctor() +43
   Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(Action`1 startup) +30
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +70
   System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +115
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +106
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +418
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

谢谢, 哈恰图尔

【问题讨论】:

  • 可以是中等信任的托管策略,stackoverflow.com/a/17218344/874427 - 请阅读。
  • 在您的服务提供商处购买专用服务器或下一级服务可能是最快的解决方案(显然不是这样回答),因为您似乎需要完全信任才能运行应用程序。
  • 听起来像是一个共享主机,它不会给你完全信任(这是对所有内容的完全访问/权限的 .NET 名称)。您可能可以在自己的 web.config 文件中重现 <trust level="Medium" /> 的问题并修复安全问题(或将托管切换到您自己的专用服务器,您可以在其中根据需要授予权限)。
  • 我尝试将信任级别设置为完全,但管理员已锁定对此的访问权限。
  • @Khachatur, trust level="Medium" 不再受支持。 Refer this answer

标签: c# asp.net-mvc asp.net-mvc-5


【解决方案1】:

感谢您的回答。看起来我无法将 MVC5 与我的托管服务 (hostgator) 一起使用。

当前版本的 ASP.NET 现在只支持完全信任。女士有 发布说明:“ASP.NET MVC 5 不再存在的已知问题”中所述 支持部分信任...."。特别是 [程序集: AllowPartiallyTrustedCallers] 属性已从 源代码。你可以阅读更多关于 ASP.NET 的官方立场在 Levi 对 is-trying-to-develop-for-medium-trust-a-lost-cause 的回答是, 其中还包括有关为何移除支持的更多链接。

见: Deploying ASP.NET MVC Project

【讨论】:

  • 我刚刚注册了 HostGator 进行试用,遇到了同样的问题。他们有一个page,我们可以看到任何依赖完全信任(以及因此反射)的东西都不会在共享主机上运行,​​包括 MVC 5 和 MVC Owin。我想我会留在 Arvixe 或转向专用托管。
猜你喜欢
  • 1970-01-01
  • 2014-12-17
  • 2011-01-13
  • 2015-11-29
  • 1970-01-01
  • 2016-01-04
  • 2016-11-15
相关资源
最近更新 更多