Search code examples
c#asp.net-mvcsecurityhostingshared-hosting

Unable to read/write files in shared hosting (hostgator)


I have developed MVC 5 project it works fine on local file server and on other hostings like (dhosting, Go daddy) but when i upload it to shared hosting(hostgator) it throws an security exception i.e.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

when i add <trust level="Full" /> the error changes to Configuration Error i.e.

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: This configuration section cannot be used at this path. This happens when the site administrator has locked access to this section using from an inherited configuration file.

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.

Is there any way to resolve this issue or should i talk to the hosting provider to provide full trust ?


Solution

  • The behavior you see is expected - most (if not all) shared hosting providers will not allow full trust sites in part due to ability to write to disk.

    Your options:

    • stop using disc and store data to DB (with added benefit if being able to actually migrate between servers, backup...)
    • dedicated server hosting (either virtual servers, VMs in Azure/Amazon/Google clouds,...) - cost will be significantly higher than medium trust shared hosting
    • find some shared hosting that allows full trust (also likely it would mean zero guarantees for availability/performance)