Last active
January 15, 2022 21:26
-
-
Save nehemiahj/04d15f3797f15ae9f203d486238debf6 to your computer and use it in GitHub Desktop.
Sitecore Site Definition Viewer Admin Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" AutoEventWireup="false" Debug="true" %> <%@ Import Namespace="Sitecore.Sites" %> <%@ Import Namespace="Sitecore.Text" %> <%@ Import Namespace="System.Linq" %> | |
<script runat="server" language="c#"> | |
public SiteCollection siteCollection; | |
public Site selectedSiteObj; | |
/// <summary> | |
/// Page Load event handler. | |
/// </summary> | |
protected override void OnLoad(EventArgs e) | |
{ | |
base.OnLoad(e); | |
CheckSecurity(); | |
InitializeSites(); | |
Results.Visible = false; | |
if (Page.IsPostBack == false) | |
{ | |
LoadSites(); | |
} | |
} | |
private void InitializeSites() | |
{ | |
ConfigSiteProvider provider = new ConfigSiteProvider(); | |
var collection = new System.Collections.Specialized.NameValueCollection(); | |
collection.Add("siteList", "sites"); | |
collection.Add("checkSecurity", "false"); | |
provider.Initialize("sitecore", collection); | |
siteCollection = provider.GetSites(); | |
} | |
/// <summary> | |
/// Load Dropdown | |
/// </summary> | |
protected void LoadSites() | |
{ | |
ddlSiteName.DataSource = siteCollection.Select(x=>x.Name).ToList(); | |
ddlSiteName.DataBind(); | |
ddlSiteName.Items.Insert(0, new ListItem("--Select Site--", "--Select Site--")); | |
ddlSiteName.SelectedIndex = 0; | |
} | |
/// <summary> | |
/// Gets the site definition with inheritance | |
/// </summary> | |
public void ddlSiteName_SelectedIndexChanged(object sender, EventArgs e) | |
{ | |
string selectedSite = ddlSiteName.SelectedItem.Text; | |
if (!string.IsNullOrEmpty(selectedSite) && selectedSite != "--Select Site--") | |
{ | |
selectedSiteObj = siteCollection.First(x => x.Name == selectedSite); | |
if (selectedSiteObj != null) | |
{ | |
Results.Visible = true; | |
string parentSiteName = selectedSiteObj.Properties["inherits"]; | |
if (!string.IsNullOrEmpty(parentSiteName)) | |
{ | |
var parentSite = siteCollection.First(x => x.Name == parentSiteName); | |
if (parentSite != null) | |
{ | |
foreach (var parentProperty in parentSite.Properties) | |
{ | |
if (!selectedSiteObj.Properties.ContainsKey(parentProperty.Key)) | |
{ | |
selectedSiteObj.Properties[parentProperty.Key] = parentProperty.Value; | |
}}}}} | |
else | |
{ | |
Results.Visible = false; | |
} | |
} | |
else | |
{ | |
Results.Visible = false; | |
} | |
} | |
/// <summary> | |
/// Checks the security. | |
/// </summary> | |
protected void CheckSecurity() | |
{ | |
if (Sitecore.Context.User.IsAdministrator) | |
{ | |
return; | |
} | |
SiteContext site = Sitecore.Context.Site; | |
string url = (site != null) ? site.LoginPage : string.Empty; | |
string pageUrl = string.Format("/sitecore/admin/sitedefviewer.aspx{0}", (string.IsNullOrEmpty(this.Request.QueryString.ToString()) ? string.Empty : "?" + this.Request.QueryString.ToString())); | |
url += "?returnUrl=" + this.Server.UrlEncode(pageUrl); | |
if (url.Length > 0) | |
{ | |
Response.Redirect(url, true); | |
} | |
} | |
</script> | |
<!DOCTYPE html> | |
<html> | |
<head runat="server"> | |
<title>Site Definition Viewer</title> | |
<link rel="shortcut icon" href="/sitecore/images/favicon.ico" /> | |
<sc:platformfontstyleslink runat="server" /> | |
<link rel="Stylesheet" type="text/css" href="/sitecore/shell/themes/standard/default/WebFramework.css" /> | |
<script type="text/javascript" src="/sitecore/shell/controls/lib/jQuery/jquery.js"></script> | |
</head> | |
<body> | |
<form id="form1" runat="server" class="wf-container"> | |
<div class="wf-content"> | |
<h1>Site Definition Viewer</h1> | |
<p class="wf-subtitle">Lets you view the Site definition after resolving site inheritance.</p> | |
<div class="wf-configsection"> | |
<h2>Select Site</h2> | |
<p> | |
<asp:DropDownList runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlSiteName_SelectedIndexChanged" ID="ddlSiteName" Width="100%"></asp:DropDownList> | |
</p> | |
</div> | |
<asp:Panel ID="Results" runat="server" Visible="False"> | |
<div class="wf-configsection"> | |
<h2>Result</h2> | |
<table border="1" style="border-collapse: collapse;"> | |
<tr> | |
<th>Key</th> | |
<th>Value</th> | |
</tr> | |
<% if (selectedSiteObj != null){ foreach (var prop in selectedSiteObj.Properties) { Response.Write(String.Format("<tr><td>{0}</td><td>{1}</td></tr>", prop.Key, prop.Value)); } } %> | |
</table> | |
</div> | |
</asp:Panel> | |
</div> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment