0

I'm coming from VB.NET webforms on .NET 4 to C# and ASP.NET Core 6 Razor pages.

Our users authenticate via network information injected in the headers.

Previously we'd check for a valid header in global.asax. If it was valid we'd allow them to view the address they typed.

User goes to myAwesomePage.aspx

'global.asax
If HttpContext.Current.Session Is Nothing then
    'log the user in using header data
else 
    'go to newAccount.aspx
end if

In Razor, I can't seem to allow the user to get to myAwesomePage.cshtml

//program.cs
builder.Services.AddAuthentication("myApp")
    .AddCookie("myApp", options =>
    {
        options.Cookie.Name = "myApp";
        options.LoginPath = "/Account/Login";
        // can I get the intended page here somehow? I don't think I can...
    });

//login
public async Task<IActionResult> OnGetAsync(){
    string referer = HttpContext.Request.Headers["Referer"].toString(); //this is always "" so I can't use it to redirect the user.
    //other code
}

How do I authenticate the user and redirect using razor? TIA.

2

1 Answer 1

0

My original attempt that I got from here: Asp.Net Core url referer is empty wasn't working. Changing

HttpContext.Request.Headers["Referer"].toString();

to

HttpContext.Request.Query["returnUrl"]

Solved the problem.

Headers["Referer"] vs Query["returnUrl"] is a problem for another day.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.