尝试将我的网站部署到 Azure,Signalr 在浏览器上显示以下错误:
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
对于本次通话:
hubs/presence/negotiate?negotiateVersion=1:1
随后:
Error: Failed to complete negotiation with the server: Error: The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.: Status code '405'
以下是端点:
app
.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<PresenceHub>("hubs/presence");
});
该网站在 https 上运行,url 定义如下:
export const environment = {
production: true,
apiUrl:'https://vidcallme.azurewebsites.net/api/',
hubUrl:'https://vidcallme.com/hubs/',
baseUrl:'/'
};
API 可以工作,但集线器却不能。
这是 Api web.config
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\API.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
客户端是用 Angular 编写的。
这是我的客户端 web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<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="/" />
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<verbs allowUnlisted="true">
<add verb="POST" allowed="true" />
</verbs>
</requestFiltering>
</security>
</system.webServer>
</configuration>
最佳答案
你这边的问题。它显示允许:GET、HEAD、OPTIONS、TRACE
,但POST
除外。这就是原因。
您可以引用下面的代码。
<security>
<requestFiltering>
<verbs allowUnlisted="true">
<add verb="POST" allowed="true" />
</verbs>
</requestFiltering>
</security>
关于azure - Azure 上托管的 Signalr 给出 405 不允许的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71841824/