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.