• GoDaddy Community
  • VPS & Dedicated Servers
  • VPS & Dedicated Servers

    cancel
    Showing results for 
    Show  only  | Search instead for 
    Did you mean: 
    Go to solution
    Highlighted

    ServiceStack: getting Security Exception for System.Security.Permissions.ReflectionPermission

    Hello

    I've got a web app which uses ServiceStack. On my local machine everything works great. BUT! When I'm deploying it to my hosting and trying to open url of my webservice I'm getting following error:

     

    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: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
    
    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: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
       System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
       System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) +34
       System.Security.CodeAccessPermission.Demand() +46
       System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Module m, StackCrawlMark& stackMark, Boolean skipVisibility) +243
       System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Module m, Boolean skipVisibility) +48
       ServiceStack.Text.ReflectionExtensions.GetConstructorMethodToCache(Type type) +586
       ServiceStack.Text.ReflectionExtensions.GetConstructorMethod(Type type) +68
       ServiceStack.Text.ReflectionExtensions.CreateInstance(Type type) +8
       ServiceStack.ServiceHost.ServiceController.RegisterNServiceExecutor(Type requestType, Type serviceType, ITypeFactory serviceFactoryFn) +123
       ServiceStack.ServiceHost.ServiceController.RegisterNService(ITypeFactory serviceFactoryFn, Type serviceType) +287
       ServiceStack.ServiceHost.ServiceController.Register(ITypeFactory serviceFactoryFn) +96
       ServiceStack.ServiceHost.ServiceManager.Init() +50
       ServiceStack.WebHost.Endpoints.AppHostBase.Init() +43
       DarkMindFx.Global.Application_Start(Object sender, EventArgs e) +571

    So it seems like the problem is that ServiceStack cannot perform the reflection to get my service classes from his own assembly and fails on start.

    I've tried to add following line to my we.config:

    <location path="api">
    ....
        <system.web>
    ....
          <securityPolicy>
            <trustLevel name="Full" policyFile="internal"/>
          </securityPolicy>
    ....
      <system.web>
    </location>

    BUT again! I'm getting this kind of error:

    Configuration Error
    
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 
    
    Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS.
    
    Source Error: 
    
    
    An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
    
    Source File: G:\PleskVhosts\mysite.com\httpdocs\DSHost.Backend\web.config    Line: 17 

    where Line 17 is <securityPolicy> tag.

    So I'm lost. Could someone please help me - how can I make my ServiceStack-base application running?

     

    1 ACCEPTED SOLUTION

    Accepted Solutions
    Highlighted
    Moderator
    Moderator
    Solution

    Re: ServiceStack: getting Security Exception for System.Security.Permissions.ReflectionPermission

    Hi Gloubs000, thanks for posting!

     

    This depends on what hosting plan you are using. If you are using a Plesk hosting plan, it can be configured to use Full Trust. This setting should be managed directly through Plesk. See the steps in the second section of this article:

    https://www.godaddy.com/help/what-trust-level-can-i-use-when-running-aspnet-2531

     

    If you aren't using Plesk, you can try adding this to your web.config instead:

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

     

    Perhaps some of our other community members that are more familiar with ASP.NET will have some other suggestions.

    ^Gary

    Gary - GoDaddy | Community Moderator
    24/7 Support | Check System Status

    View solution in original post

    1 REPLY 1
    Highlighted
    Moderator
    Moderator
    Solution

    Re: ServiceStack: getting Security Exception for System.Security.Permissions.ReflectionPermission

    Hi Gloubs000, thanks for posting!

     

    This depends on what hosting plan you are using. If you are using a Plesk hosting plan, it can be configured to use Full Trust. This setting should be managed directly through Plesk. See the steps in the second section of this article:

    https://www.godaddy.com/help/what-trust-level-can-i-use-when-running-aspnet-2531

     

    If you aren't using Plesk, you can try adding this to your web.config instead:

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

     

    Perhaps some of our other community members that are more familiar with ASP.NET will have some other suggestions.

    ^Gary

    Gary - GoDaddy | Community Moderator
    24/7 Support | Check System Status

    View solution in original post