Add AccessDenied page

This commit is contained in:
danial23 2025-05-20 11:49:59 -04:00
parent bc62310104
commit 8e0a380dea
Signed by: danial23
SSH key fingerprint: SHA256:IJ8VP0j2WMUVweTYnzUUnEjNgPnGx+mAt+RhqWZ01bU
2 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1,11 @@
@page
@model CSR.WebUI.Pages.AccessDeniedModel
@{
ViewData["Title"] = "Access Denied";
}
<div class="text-danger">
<h1 class="text-danger">Access Denied</h1>
<p class="text-danger">You do not have permission to access @Model.ResourceName.</p>
<p>If you believe this is an error, please contact your administrator.</p>
</div>

View file

@ -0,0 +1,25 @@
namespace CSR.WebUI.Pages;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Web;
public class AccessDeniedModel : PageModel
{
public string ResourceName { get; set; } = "the requested resource"; // Default message
public void OnGet(string returnUrl)
{
if (!string.IsNullOrEmpty(returnUrl))
{
// Decode the URL if it was encoded
var decodedUrl = HttpUtility.UrlDecode(returnUrl);
var uri = new Uri("http://localhost" + decodedUrl); // Use a base URI to help with parsing
ResourceName = uri.Segments.Length > 1 ? uri.Segments.Last() : "the requested resource";
if (string.IsNullOrEmpty(ResourceName))
{
ResourceName = "the requested resource";
}
}
}
}