2
votes

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 ?

3
Consindering This happens when the *site administrator* has locked access to this section using from an inherited configuration file. - yes, I'd say you'd need to talk to the hosting provider - Rob
Thanks Rob, i've read that the hosting i'm using only supports medium trust but my application requires full trust. So may be i should consider another hosting that gives full access. - Asad Shah

3 Answers

1
votes

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)
0
votes

The trick is working all in the memory, in my case I'm creating a Excel File using the EPPlus Library

        var stream = new MemoryStream(package.GetAsByteArray());

        Response.AppendHeader("content-disposition", "attachment; filename=MyFile.xlsx");
        Response.ContentType = "application/octet-stream";
        Response.BinaryWrite(stream.ToArray());
        Response.End();
0
votes

I had the same problem with Hostgator. Windows Shared hosting plan.

  • You get the Parser Error Message simply because you can't modify the trust level in your web.config file. (this is why it changes to configuration error)
  • The CAS trust level setting in Hostgator Plesk is only placebo.
  • Solution: you should change the permissions of that folder to full control you want to write into. (you can do that in Plesk).

Then you can go:

File.Create(@"D:\InetPub\vhosts\<yourdomain>\httpdocs\App_Data\file.txt");

I see that it's been a year since you asked this. Did you manage to create files since then?