I
I
iamdivine2021-11-11 09:38:16
ASP.NET
iamdivine, 2021-11-11 09:38:16

How do I sign in to Razor Pages?

Good afternoon !
A friend has a website, there are only 4 pages and there is authorization.
Passwords are stored in the database hashed md5.
There are many users.
It is necessary to use the authorization check on page 1.
I also found in the documentation how to do this, but as I understand it, it only works for Identy

using System;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages(options =>
{
    options.Conventions.AuthorizePage("/user");
});

builder.Services.AddSession(options =>
{
    options.IdleTimeout = TimeSpan.FromMinutes(1800);
    //options.Cookie.HttpOnly = true;
    //options.Cookie.IsEssential = true;
});

builder.Services.AddDistributedMemoryCache();

builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
builder.Services.AddAuthorization();


var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}


app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();
app.UseAuthentication();
app.UseSession();

app.MapRazorPages();

app.Run();

I think putting Identy is not an option because you need the most basic functions to work with your account

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Volkotyuk, 2021-11-12
@iamdivine

Create two authorization options on test projects, after which you can choose which one suits you best.
https://youtu.be/7zaKdNqGzk8?list=PLUTrDHuvZc4EDn8... - creation from scratch, will allow you to understand at a low level.
https://metanit.com/sharp/aspnet5/15.5.php - authorization by roles. Also on this resource 4 more different ways of authorization are provided.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question