0

I am testing the WebApp authentication using simple cookie. The app has 2 areas: Public & Internal (see Area structure at the end of this post). Users are required to login when accessing all pages under the "Internal" area.

PROGRAM DESCRIPTION

The App is implemented with .NET 6 with Razor pages (without MVC). In the program.cs file, I tried to specify the "authorize" at the "Area" level for "Internal" area (see code segment here). The HTML 404.15 error occurred when testing the app (see HTML error in attached image below).

It looks like that "AuthorizeAreaFolder" works fine with any folder name inside of Internal area. Is there a way to setup "Authorize" at an Area level?

CONFIGURE AUTHORIZE

builder.Services.AddRazorPages(options =>
{
    options.Conventions.AuthorizeAreaFolder("Internal","/");
});

HTML ERROR enter image description here

WEBAPP AREAS

enter image description here

bedrock
  • 263
  • 1
  • 2
  • 15
  • Check this thread: https://stackoverflow.com/questions/28483745/http-error-404-15-not-found-because-the-query-string-is-too-long – Mike Brind Mar 25 '22 at 07:19
  • 1
    @mike-brind: Thanks for the info you provided. It did fixed the problem with 404.15 error. After added the [AllAnanymous] in the SignIn.cs program, the config setting of "options.Conventions.AuthorizeAreaFolder("Internal","/");" is working now. This allows me to set the "authorize" at the Area level. Please change your comments to the answer to my posted question, so that I can make it as resolved. – bedrock Mar 25 '22 at 14:04

1 Answers1

0

Make sure that your signing in page is accessible to anonymous users. An easy way to accomplish this is to add the AllowAnonymous attribute to the PageModel class of the relevant page e.g (assuming the signing in page is called Signin):

[AllowAnonymous]
public class SigninModel : PageModel
Mike Brind
  • 28,238
  • 6
  • 56
  • 88