Blazor server app - How to loop through request server variables

Andres Leon 1 Reputation point
2022-10-20T14:41:45.26+00:00

In ASP.NET, you can loop through all server variables by running this:

foreach (string s in Request.Params.Keys)  
     s.ToString() + " - " + Request.Params[s];  

How can I do the same thing in a Blazor server app? i am trying to get a list of all server variables (and session variables, too) in my login.cshtml page (which has been scaffolded).

Thanks.

Developer technologies .NET Blazor
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-10-20T15:45:20.583+00:00

    asp.net core did not implement server variables (as they are closely tied to IIS support). in asp.net core the server variables are the request headers (IIS may add headers to the request), or are in the HttpContext.Connection object (accessed via injection). As blazor is stateful, there typically is no need for session variables.

    note: for blazor server uses signal/r for client/server communication, so there is just one standard request to open the connection and create the server state and thread tied to the connection.

    1 person found this answer helpful.
    0 comments No comments

  2. Andres Leon 1 Reputation point
    2022-10-20T16:17:55.077+00:00

    Hello Bruce,
    Thank you for your prompt response! Much appreciated.

    In my blazor server app I had to scaffold the login page so that I could implement my own authentication. Based on what I see in the code, this page does not use signal-r for communication and still uses the typical http get/post to send the login info. Once the login is successful it redirects to the original default page which then initiates the signal-r connection.

    If this is correct, then i should be able to get some header variables from the login.cshtml page. right?

    0 comments No comments

  3. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-10-20T19:59:17.377+00:00

    there will be a httpcontext in either case.

    oauth, because it seldom supports iframe, typically is a redirect to the login server, which will redirect back to server hosting blazor. if you use individual accounts, it is cookie based, and the login pages are typically server pages.

    the AuthenticationStateProvider returns authentication data to the blazor app. The default implementation looks at Context.User which would be set by oauth or cookie authentication. but you can provide a custom implementation, and use an alternative authentication approach.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.