如何将 Web API 与 HostGator Windows 共享计划一起使用?

How to use Web API with HostGator Windows shared plan?

我有一个 HostGator 的共享计划。我想在我的站点上创建 Web API 服务,但由于安全问题它崩溃了:

Url:

http://example.com/api/welcome/Mitulat

代码:

// GET api/welcome/5
public string Get(string id)
{
    return "Hello " + id + "!";
}

web.config 文件:

 <system.web>
   <customErrors mode="Off"/>
   <compilation targetFramework="4.5" />
   <httpRuntime targetFramework="4.5" />
 </system.web>

它在本地有效,但当我将其上传到服务器时,页面显示:

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.

支持人员表示应用程序必须以中等信任级别发布,因此我将此行添加到 web.config 文件的 <system.web> 部分:

<trust level="Medium"/>

现在页面显示:

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.

支持说我不应该使用这个功能。难道是真的吗?我的意思是 HostGator 服务于数百万个网页。我敢打赌他们中的一些人使用 Web API... 我卡住了。

经过 2 天的研究,与 "support" 的 3 次对话,以及精神崩溃,我基于这个问题成功地在 Hostgator 共享计划中执行了 Web API 请求。

没有这个我不知道我会做什么...

简介:

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.