Skip to content

Instantly share code, notes, and snippets.

@jeremy-farrance
Last active August 8, 2021 18:04
Show Gist options
  • Save jeremy-farrance/75896f35df01d6caf1d1cb89936f8f13 to your computer and use it in GitHub Desktop.
Save jeremy-farrance/75896f35df01d6caf1d1cb89936f8f13 to your computer and use it in GitHub Desktop.
A DNN Theme footer include file that outputs useful Debug info for OHS, development, etc. C#, CSharp, .NET
<%-- THIS IS THE C# CSharp .NET VERSION
NOTES:
- the way we get the Skin name is "janky" ;)
- uses Bootstrap (next version won't?)
How to use:
1. Save this file in your theme folder, usually includes/__debug.ascx
2. Update the IPs; add the WAN IP(s) for your location(s)
3. Update the Bootstrap version manually
4. Either in includes/_footer.ascx (or Home.ascx), before closing DIV in main <footer> section add this
<!-- #include virtual="__debug.ascx" -->
5. To view the output when NOT at an allowed IP, just add /debug/on to your URL
FUTURE: no Bootstrap
--%>
<% if (UserCanViewDebug()) { %>
<div class="alert alert-warning m-0 text-monospace" role="alert">
<%-- DNN / HOST --%>
<div class="mb-2">
<p>DNN <%=DotNetNuke.Application.DotNetNukeContext.Current.Application.Version.ToString(3) %> / <%=System.Environment.Version.ToString() %> / Host=<%=System.Net.Dns.GetHostName() %></p>
</div>
<%-- THEME --%>
<div class="mb-2">
<p>Theme:
Skin=<strong><%=PortalSettings.DefaultPortalSkin.Split('/')[1].ToUpper() %></strong>,
Layout/Container=<span title="<%=PortalSettings.ActiveTab.SkinSrc %>"><%=System.IO.Path.GetFileNameWithoutExtension(PortalSettings.ActiveTab.SkinSrc) %></span>/<span title="<%=PortalSettings.ActiveTab.ContainerSrc %>"><%=System.IO.Path.GetFileNameWithoutExtension(PortalSettings.ActiveTab.ContainerSrc) %></span>,
Bootstrap=<span title="no plans to upgrade Bootstrap to v5 - 20210808 JRF">v4.6</span>
</p>
</div>
<%-- PAGE --%>
<div class="">
<p class="mb-1">Page: TabID=<%=PortalSettings.ActiveTab.TabID %>, Name=<%=PortalSettings.ActiveTab.TabName %>, Title=<%=PortalSettings.ActiveTab.Title %></p>
<div class="px-3">
<div class="mb-0">Status:
<span title="Display in Menu/Nav">IsVisible=<%=PortalSettings.ActiveTab.IsVisible %>, </span>
<span>Published=<%=PortalSettings.ActiveTab.HasBeenPublished %> </span>
</div>
<p class="mb-0">
Nav: Level=<%=PortalSettings.ActiveTab.Level %>,
Path=<%=PortalSettings.ActiveTab.TabPath %>,
<span title="Disabled in Menu/Nav (e.g. not a link)">DisableLink=<%=PortalSettings.ActiveTab.DisableLink %> </span>
</p>
<p class="mb-0">QueryString pairs: <%=Request.QueryString.ToString().Replace("&",", ") %></p>
</div>
</div>
<hr />
<%-- SMALL PRINT --%>
<div class="small text-dark">
<p class="mb-0">
Using <code><%=System.Configuration.ConfigurationManager.AppSettings["UpdateServiceUrl"] %></code> for updates.
Deployed on <%=System.Configuration.ConfigurationManager.AppSettings["InstallationDate"] %>
at Dnn version <%=System.Configuration.ConfigurationManager.AppSettings["InstallVersion"] %>,
</p>
<p>WAN IP: <%=GetIpAddress() %>, page output <%=DateTime.Now.ToString("F") %></p>
</div>
<p class="small font-weight-bold mt-2 mb-0">Debug info only visible from ASL WAN IP addresses and being output from <code>includes/_footer.ascx</code> in Skin.</p>
</div>
<% } %>
<script runat="server">
public bool UserCanViewDebug()
{
var list = new List<string> {
"127.0.0.1", // localhost
"192.241.63.162", // 309SN
};
return list.Contains(GetIpAddress()) || UrlOverride();
}
public bool UrlOverride(string urlParamName = "debug", string urlParamValue = "on")
{
return Request.QueryString[urlParamName] == urlParamValue;
}
public string GetIpAddress()
{
string stringIpAddress;
stringIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (stringIpAddress == null)
{
stringIpAddress = Request.ServerVariables["REMOTE_ADDR"];
}
return stringIpAddress;
}
</script>
@jeremy-farrance
Copy link
Author

Typical output looks something like this:

image

@jeremy-farrance
Copy link
Author

Improved output May 2021:
image

@jeremy-farrance
Copy link
Author

Improved output Aug 2021
image

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