0

I got security exception when deploying the default MVC 5 app generated with VS 2013 to my hosting account.

Is there any quick solution for this problem?

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

Thanks, Khachatur

Khachatur
  • 921
  • 1
  • 12
  • 30
  • 1
    Can be a medium trust hosting policy, http://stackoverflow.com/a/17218344/874427 - read that. – Johnny Nov 29 '14 at 07:28
  • Buying dedicated server or next level of service on your service provider is probably the quickest solution (not SO answer obviously) as you seem to need full trust to run the application. – Alexei Levenkov Nov 29 '14 at 07:28
  • 1
    Sounds like a shared hosting which does not give you full-trust (which is the .NET name for full access/permissions to everything). You can probably reproduce the problem with `` in your own web.config file and fix the security issues (or switch hosting to your own dedicated servers where you can give permissions as you want). – sisve Nov 29 '14 at 07:28
  • I have tried to set trust level to full but then got administrator has locked access to this. – Khachatur Nov 29 '14 at 07:31
  • @Khachatur, `trust level="Medium"` is no longer supported. [Refer this answer](http://stackoverflow.com/questions/25347092/deploying-asp-net-mvc-project/25354496#25354496) –  Nov 29 '14 at 07:35

1 Answers1

3

Thanks for your answers. It looks like I cannot use MVC5 with my hosting service (hostgator).

The current versions of ASP.NET now only support full trust. MS have stated in Release Notes: Known Issues that "ASP.NET MVC 5 no longer supports partial trust....". In particular the [assembly: AllowPartiallyTrustedCallers] attribute has been removed from the source code. You can read more about ASP.NET's official position in Levi's answer to is-trying-to-develop-for-medium-trust-a-lost-cause, which also includes further links to why support has been removed.

See: Deploying ASP.NET MVC Project

Community
  • 1
  • 1
Khachatur
  • 921
  • 1
  • 12
  • 30
  • I've just signed up for HostGator for a trial, and had the same problem. They have a [page](http://support.hostgator.com/articles/hosting-guide/hardware-software/compatible-technologies-windows) where we can see that anything that depends on Full Trust (and consequently Reflection) will not run on shared hosting, including MVC 5 and MVC Owin. I guess I'll stay with Arvixe or move to dedicated hosting. – drizin Jan 26 '16 at 17:52