Thursday, December 22, 2022

Unauthorized access access denied redirect to URL ASP.NET C#

web.config



<customErrors mode="On" defaultRedirect="~/GenericErrorPage.htm" >

  <error statusCode="401" redirect="~/unauthorized.htm"/>

 </customErrors>





aspx.cs code

protected void Page_Load(object sender, EventArgs e)

{



if (!Page.IsPostBack)

{

if (Request.IsAuthenticated && !string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))

Response.Redirect("~/unauthorized.aspx");

}

}


or


public static bool CheckPageAccess(string uRL, long roleCode)
        {
            bool IsAllow = false;

            if (HttpContext.Current.Session[Constants.UserInformation] != null)
            {
                IsAllow = MenuService.MenuAccess(uRL, roleCode);
            }

            return IsAllow;
        }

if (!PageUtils.CheckPageAccess(Request.Url.AbsolutePath, CurrentUser.RoleMasterId))
                {
                    Response.Redirect("~/UnauthorizedAccessError.aspx?contentPage=" + Request.RawUrl);
                }

                if (!string.IsNullOrWhiteSpace(Request.QueryString["ApplicationId"]))
                {
                    ApplicationId = Convert.ToInt64(CryptologyFunctions.Decrypt(Request.QueryString["ApplicationId"]));

                }

No comments:

Post a Comment