azure - Azure 上托管的 Signalr 给出 405 不允许的方法

标签 azure asp.net-core signalr asp.net-core-5.0

尝试将我的网站部署到 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>

相关: SignalR Error 405 (method not allowed) - Negotiate

最佳答案

你这边的问题。它显示允许:GET、HEAD、OPTIONS、TRACE,但POST除外。这就是原因。

enter image description here

您可以引用下面的代码。

<security>
  <requestFiltering>
    <verbs allowUnlisted="true">
      <add verb="POST" allowed="true" />
    </verbs>
  </requestFiltering>
</security>

关于azure - Azure 上托管的 Signalr 给出 405 不允许的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71841824/

相关文章:

Azure AD : id_token as bearer token

caching - 当文件从 VirtualPathProvider 作为 Stream 返回时维护文件的缓存控制属性

具有预定义值的 Azure Policy 标记

javascript - 如何从 Javascript 检索 Azure Active Directory 登录的用户信息?

c# - 注册模块 Autofac

asp.net-core - SignalR hub 在 ASP.NET Core 中的 RabbitMQ 订阅处理程序中解析为 null

c# - 是否可以有多个仅因 ASP.NET Core 中的参数而异的 GET?

asp.net-core - 为什么 "IApplicationBuilder"找不到 "UseGraphQL"的定义?

c# - 自定义 SignalR 的错误消息

asp.net-core - 来自 asp.net core 2.2 信号器控制台应用程序的服务器集线器连接