不允许进行Plesk IIS POST

问题描述 投票:0回答:1

因此,我在远程服务器上部署了自托管WEB API,每当尝试调用POST方法时,都会收到405响应。在我的研究中,我发现需要禁用WebDAV模块,但到目前为止对我而言仍然无效。

这是我的web.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <remove name="OPTIONSVerbHandler" />
            <remove name="TRACEVerbHandler" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
        <rewrite>
            <rules>
                <rule name="Redirects to www.domain.com" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_HOST}" pattern="^admin.domain.com$" />
                    </conditions>
                    <action type="Redirect" url="https://admin.domain.com/{R:0}" />
                </rule>
                <rule name="Angular Routes" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.html" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

这是我启动WEB Api的主要方法:

public static void Main(string[] args) 
{
    var cors = new EnableCorsAttribute("http://localhost:4300,https://admin.domain.com", "*", "GET,POST");

    // Set up server configuration
    HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(_baseAddress);
    config.MessageHandlers.Add(new CustomHeaderHandler());
    config.EnableCors(cors);
    config.MapHttpAttributeRoutes();
    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
        );

    var server = new HttpSelfHostServer(config);
    // Start listening
    server.OpenAsync().Wait();
    Console.WriteLine("Web API Self hosted on " + _baseAddress + " Hit ENTER to exit...");
    Console.ReadLine();
    server.CloseAsync().Wait();
}

CustomHeaderHandler类如下:

public class CustomHeaderHandler : DelegatingHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
    {
        return base.SendAsync(request, cancellationToken)
            .ContinueWith((task) =>
                {
                    HttpResponseMessage response = task.Result;
                    response.Headers.Add("Allow", "GET, POST");
                    return response;
                });
    }
}

[每当我尝试POST时,都会收到以下响应标头:

allow: GET, HEAD, OPTIONS, TRACE
content-length: 1293
content-type: text/html
date: Wed, 26 Jun 2019 11:12:14 GMT
server: Microsoft-IIS/10.0
status: 405
x-powered-by: ASP.NET
x-powered-by-plesk: PleskWin

我也尝试过这里提出的解决方案:How to remove WebDAV module from IIS?

而且我也尝试了此解决方案:

<modules>
  <remove name="WebDAVModule"/>
</modules>
<handlers>
  <remove name="WebDAV" />
</handlers>

有人知道这个问题可能是什么吗?托管处的家伙告诉我,我应该添加一个处理程序,但是我对我做错了事感到茫然。

提前感谢。

asp.net iis plesk iis-10
1个回答
0
投票

我遇到同样的问题。您正在寻找的web.config修改是

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <modules runAllManagedModulesForAllRequests="false">
        <remove name="WebDAVModule" />
      </modules>
      <aspNetCore ... />
    </system.webServer>
  </location>
</configuration>

但是,.NET Core 3.0和3.1在项目中不带有web.config。 web.config在发布时生成。我在发布后手动添加了模块标签,但是每次发布Web应用程序时都不能一遍又一遍地添加此代码块。

© www.soinside.com 2019 - 2024. All rights reserved.