Application Security Change for Medium Trust

1

Recently I uploaded a system I created in Asp.Net using MVC and Entity to the KingHost web server. On localhost and on my own server it works normally. When trying to access the application on the KingHost server, it gives the following error:

  

[SecurityException: Type permission request failed   'System.Web.AspNetHostingPermission, System, Version = 4.0.0.0,   Culture = neutral, PublicKeyToken = b77a5c561934e089 '.]
  System.Security.CodeAccessSecurityEngine.Check (Object demand,   StackCrawlMark & stackMark, Boolean isPermSet) +0
  System.Security.CodeAccessSecurityEngine.Check (CodeAccessPermission   cap, StackCrawlMark & stackMark) +31
  System.Security.CodeAccessPermission.Demand () +46
  System.Web.Hosting.HostingEnvironment.get_ApplicationID () +62
  Microsoft.Owin.Host.SystemWeb.OwinAppContext..ctor () +63
  Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build (Action% co_of% 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

By searching I could see the following: On the server you can configure the security policies in Web.config that is in the% windir% \ Microsoft.NET \ Framework {version} \ CONFIG \ directory of the server (even in localhost vc can set this). Usually looks like this:

<location allowOverride="true">
  <system.web>
    <securityPolicy>
      <trustLevel name="Full" policyFile="internal" />
      <trustLevel name="High" policyFile="web_hightrust.config" />
      <trustLevel name="Medium" policyFile="web_mediumtrust.config" />
      <trustLevel name="Low" policyFile="web_lowtrust.config" />
      <trustLevel name="Minimal" policyFile="web_minimaltrust.config" />
      <trustLevel name="Custom" policyFile="web_CustomTrust.config" />
    </securityPolicy>
    <trust level="Full" originUrl="" /> <--aqui eu digo o nível que as app vão usar-->>
  </system.web>
</location>

My default application was created as Full Trust. As the KingHost server is set to Medium Trust, in my application's web.config I would only need to set the security level of my application to Medium by placing this block:

<system.web>    
    <trust level="Full"/> 
</system.web>

However, on KingHost's server they set "allowOverride = false", not allowing the application to choose which level of security it wants to use through Web.config. I can see this because after I put this code it appears this other error message:

  

This configuration section can not be used in this path. That   occurs when the site administrator blocks access to this section   using 1 startup) +30 Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +70 System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func of a configuration file   inherited.

Does anyone know how I can change my application to Medium Trust?

    
asked by anonymous 22.01.2015 / 12:30

2 answers

2

For newer Frameworks, Microsoft is discouraging Medium Trust for the sake of isolation by operating system level, as described in this support article for newer Frameworks such as Owin, if any. There are several answers from the SO talking about it, but I cite my search sources.

Or you need to negotiate with the provider a Full Trust permission, or change provider.

    
22.01.2015 / 15:24
2

I also had the same problem, I discovered that it was Itextsharp that caused this error, my solution was as follows:

  • download Itextsharp and XMLworkerHelper fonts
  • I added the following line [assembly: AllowPartiallyTrustedCallers()] to the AssemblyInfo.cs file.

These are Microsoft's own guidelines

    
19.11.2015 / 13:38