add exception filter when user not connected default to needing authentication and apply anonymous to some actions add user in get requests add user relation in link, comment and vote signup and in are ok now!
16 lines
347 B
C#
16 lines
347 B
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
|
namespace Website
|
|
{
|
|
public sealed class CustomExceptionFilter : IExceptionFilter
|
|
{
|
|
public void OnException(ExceptionContext context)
|
|
{
|
|
if (context.Exception is UserNotConnected)
|
|
{
|
|
context.Result = new UnauthorizedResult();
|
|
}
|
|
}
|
|
}
|
|
} |