– the ocelot across domains
Ocelot cross-domainCopy the code
We talked about gateway proxying through Ocelot. After I configured it and posted it to the server, all API interfaces and swaggerUI can be accessed normally. So I thought I had it all figured out. Then the front end told me of a serious problem and reported a cross-domain problem. And THEN I guess ocelot retweeted it.
Because I’ve done cross-domain processing before. In a webAPI program, all out of the process. Later, the front end was also confirmed that the interface can be used normally. The interface is all done. Later because of security problems, had to do gateway processing. Now there’s cross-domain. And it seems I guess. And it was confirmed.
This is the code I used to test cross-domain. You do find cross-domain problems with browsers when requesting via Ajax. There is no screenshot here.
And then I used Ocelot to do cross-domain. I searched the Internet very complicated such tutorials, are problematic, after writing, the code reported errors. And I’ve switched to different versions of Ocelot, and it still doesn’t work. So I tried to do it the old-fashioned way. Add cross-domain code to the Startup entry.
Add it to Configuration Services
services.AddCors(options => options.AddPolicy("CorsPolicy",
builder =>
{
builder.AllowAnyMethod()
.SetIsOriginAllowed(_ => true)
.AllowAnyHeader()
.AllowCredentials();
}));
Copy the code
Add in Configure
app.UseCors("CorsPolicy");
Copy the code
Then after normal release and deployment, it is tested. Yes, indeed.
Perfect!!!!!