Skip to content

Instantly share code, notes, and snippets.

@mguster
Last active December 9, 2016 16:55
Show Gist options
  • Save mguster/f53ecb45ed95ea9c2ba188b3daa1683a to your computer and use it in GitHub Desktop.
Save mguster/f53ecb45ed95ea9c2ba188b3daa1683a to your computer and use it in GitHub Desktop.
<script runat="server">
/// <summary>
/// Page Load event handler.
/// </summary>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
CheckSecurityPermission("/sitecore/admin/ScBasicAdminPage.aspx{0}");
InitControls();
}
/// <summary>
/// Checks if the current user has the appropriate permissions to access the admin page. If not user is redirected to the login page.
/// </summary>
/// <param name="adminPagePath">The admin page path to which the user gets redirected after successful login.</param>
protected void CheckSecurityPermission(string adminPagePath)
{
if (Sitecore.Context.User.IsAdministrator)
{
return;
}
SiteContext site = Sitecore.Context.Site;
string url = (site != null) ? site.LoginPage : string.Empty;
string pageUrl = string.Format(CultureInfo.InvariantCulture, adminPagePath, string.IsNullOrEmpty(Request.QueryString.ToString()) ? string.Empty : "?" + Request.QueryString);
url += "?returnUrl=" + Server.UrlEncode(pageUrl);
if (url.Length > 0)
{
Response.Redirect(url, true);
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment