I have a shared plan on HostGator. I would like to create Web API services on my site, but it crashes because of security issues:
Url:
http://example.com/api/welcome/Mitulat
Code:
// GET api/welcome/5
public string Get(string id)
{
return "Hello " + id + "!";
}
web.config file:
<system.web>
<customErrors mode="Off"/>
<compilation targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
Locally it works, but when I upload it to the server the page says:
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 failed.
The support said the application must be published with medium trust level, so I added this line to the <system.web>
section of the web.config
file:
<trust level="Medium"/>
Now the page says:
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
<location allowOverride="false">
from an inherited configuration file.
The support said I shouldn't use this feature. Could it be true? I mean HostGator serves millions of web pages. I bet some of them use Web API... I'm stuck.
After 2 days of research, 3 more conversation with the "support", and a nervous breakdown I successfully managed to execute Web API requests in the Hostgator shared plan based on this question.
Getting Error <location allowOverride="false"> while hosting WEB API 2 in Hostgator
Without this I don't know what I would've done...
Brief:
You can deploy even without Roslyn with no change in code. Open NuGet Package Manager window and uninstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform package and rebuild & republish. This uninstallation also removes CodeDom configuration from web.config file. This will solve your purpose. Basically this will not generate any csc.exe, vbc.exe files inside bin folder.