Skip to content

Instantly share code, notes, and snippets.

@jeremy-farrance
Last active June 2, 2021 23:15
Show Gist options
  • Save jeremy-farrance/3fd028e73a545dfbcb25005d45c398ee to your computer and use it in GitHub Desktop.
Save jeremy-farrance/3fd028e73a545dfbcb25005d45c398ee to your computer and use it in GitHub Desktop.
A Dnn RazorScript for when you can't get the URL redirect right with Dnn's page settings
@{
// Where to go
string urlRedirect = "/tabid/21?paramname=paramvalue";
if (IsAdminOrHost(Dnn.Portal.UserInfo))
{
<h5>You are in a site/CMS administration role, redirect is disabled for you.</h5>
<p>Had you been a normal user, you would have been redirected to:<br>
<strong>@urlRedirect</strong>
</p>
<p>This script now has a home <a href="https://gist.github.com/jeremy-farrance" target="_blank">on my Gists (GitHub)</a>. Cheers! - Jeremy</p>
}
else
{
Response.Redirect(urlRedirect, false);
Context.ApplicationInstance.CompleteRequest();
}
}
<p>Referrer = @Request.UrlReferrer.OriginalString</p>
@functions {
private bool IsAdminOrHost(DotNetNuke.Entities.Users.UserInfo userInfo)
{
return userInfo.IsSuperUser || userInfo.IsInRole(DotNetNuke.Entities.Portals.PortalSettings.Current.AdministratorRoleName);
}
}
@jeremy-farrance
Copy link
Author

On a new, normal page, add a Razor Host module, new script, set a useful (to you) filename, copy the code (above) in, change the urlRedirect to what you want, save, make sure its active. As long as you are an Admin or Super, the redirect doesn't fire and reminds you of what is going on.

@jeremy-farrance
Copy link
Author

If you login as Admin or Super you should see this output on the page (without redirecting).
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment