架构师_程序员_码农网

Retrieve password
Register

QQ登录

Just one step to get started

Search
Views:29762|Replies: 2
打印 上一主题 下一主题

[Information]SignalR Adds Remote Access Cross-Domain Support

[Copy link]
跳转到指定楼层
owner
发表于 2021-4-23 12:39:20| 看该作者回帖奖励|ReverseBrowse|Read Mode
Requirement: The front-end and back-end are not on the same domain, so there is a cross-domain problem, how can the front-end connect to the remote SignalR?

First, the js code is as follows:

At first try to connect will report an error as follows:

Access to fetch at 'http://localhost:27939/testHub/negotiate?negotiateVersion=1' from origin 'http://localhost:5009' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
ASP.NET Core 3.1 Add Allow Cross-Domain

The ConfigureServices code looks like this:


The Configure code is as follows:

Trying to connect again results in the following error:



Access to fetch at 'http://localhost:27939/testHub/negotiate?negotiateVersion=1' from origin 'http://localhost:5009' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
Modify the ConfigureServices code again as follows:



Problem solved!





Previous: HTTP request header Expect Detailed
Next:Contemporary Chinese Economy Midterm Exercise Course
NET, only published in the practice process, encountered technical difficulties, do not mislead others.
I 'm not sure what I'm talking about, but I'm not sure what I'm talking about
sofabed
发表于 2021-9-22 21:00:27| 看该作者
I'm not sure if I'm going to be able to do this, but I'm sure I'll be able to.
The code farmer network, only published in the process of practice, encountered technical difficulties, do not mislead others.
benching the
发表于 2022-11-16 14:46:09| 看该作者
Learning Learning Learning Learning
The code farmer network, only published in the process of practice, encountered technical difficulties, do not mislead others.
You need to log in before you can post back Log in | Register

This version of the integral rules

DISCLAIMER:
All software, programming materials or articles released by the code farmer network is limited to study and research purposes; the above content shall not be used for commercial or illegal purposes, otherwise, all the consequences please user responsible. This site information from the network, copyright dispute has nothing to do with this site. You must completely remove the above content from your computer within 24 hours of downloading. If you like the program, please support the genuine software, buy registration and get better genuine service. If there is any infringement, please contact us by email to deal with it.

Mail To:help@itsvse.com

QQ| ( ICP备14021824号-2 )|Sitemap

GMT+8, 2024-9-19 01:12

Quick ReplyBack to topBack to list