Hi @Arthur Ochoa ,
THE ISSUE: Access to HttpContext outside a Razor component returns a null value (i.e. in a separate Class file).
Please set a break point in the AuthenticateSite() method, then debug your code, the issue relates the IServiceProvider, the _services
is null. So, it will throw the ArgumentNullException: Value cannot be null. (Parameter 'provider'
error.
Try to comment or remove _services
relate code, the redirect action should work.
public void AuthenticateSite()
{
//_httpContextAccessor = _services.GetRequiredService<IHttpContextAccessor>();
_httpContextAccessor.HttpContext.Response.Redirect("https://www.site1.com/auth" + "?return_url=" + "https://www.mysite.com/blazorapp");
}
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
Dillion
Hi @AgaveJoe , thanks for the feedback.
Question, you are only referring to Blazor apps right when you said "context is only available the first time the app is downloaded."? Is that the rule only for Blazor?
All I'm doing is to execute a Response.Redirect inside a class.
Have not tried OAuth template, thanks for providing me this info.
Blazor is like any other SPA. You have the same situation with Angular, React, Vue, etc.
Blazor server is running in the browser and it uses SignalR send/receive messages. It is possible to get the context one time when the application is first loads which is why your initial code seems to work. After the initial load there are no more HTTP requests only SignalR messages.
Oh ok. Didn't know about that. Thanks much @AgaveJoe
Sign in to comment