Startup Razor page option with no UI

Robert Lovas 20 Reputation points
2023-08-25T14:15:55.3033333+00:00

When the Razor page app loads for a user, need to check to see if the person is in a SQL table, no UI is needed during this process. This app is only accessible after the user is logged into our internal network behind a firewall. I already have access to their user id. I only need to verify that they are in a table, no UI is needed. If they are in the table, I need to send them to a main menu in the app. If they are not, another page should be show.

This is how I getting the user ID, which works when the user presses ‘Button’ on the initial Razor.

I just need to do this in the start-up of the Razor Page / Application without showing the UI. Maybe in the Startup.CS class or in some load event. Maybe in the Main function in Programs.cs class. Any ideas?

Razor page code.

private async Task GetPage()
{
     {
          List<Claim> claims = new List<Claim>();

          string useridWinBase = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

          string useridWin = useridWinBase.Replace("DomainABC\\", "");
 
	 
          // this is where the check to the database table occur
          Credentials.User user = this.authService.LoginDB(Configuration, useridWin);





ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,815 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,598 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,412 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 74,696 Reputation points
    2023-08-25T15:26:01.45+00:00

    Websites are stateless. There is no load app event for a user, just a web request. You can use cookies to maintain state.

    You can add the code to the pages that require this check, or use middleware to check all requests.

    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.