Reputation: 439
I have a controller on the server side looking like this:
[HttpGet]
public IActionResult Test(string returnUrl = "/")
{
return Challenge(new AuthenticationProperties() { RedirectUri = returnUrl });
}
And when I press a button on the client side i call:
await Http.GetAsync("/api/Login/Test");
The problem is that I'm getting a cors error in the console and nothing happens. If i put in the url manually in the browser (localhost/api/Login/test) it works fine.
I added a cors policy that looks like this:
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
});
and
app.UseCors("CorsPolicy");
Which didn't make a difference.
Upvotes: 3
Views: 676
Reputation: 439
Solved it by using
@inject Microsoft.AspNetCore.Components.Services.IUriHelper UriHelper
and
UriHelper.NavigateTo("/api/Login/Test", forceLoad: true);
Upvotes: 1