Skip to content

Instantly share code, notes, and snippets.

@lowedown
Created April 13, 2016 16:13
Show Gist options
  • Save lowedown/ab7eb7d324d893258a6857d3d929163e to your computer and use it in GitHub Desktop.
Save lowedown/ab7eb7d324d893258a6857d3d929163e to your computer and use it in GitHub Desktop.
Sitecore Admin Page to test accessing URLs
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Threading.Tasks" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Test Proxy Settings</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Proxy checker</h1>
<p>Enter a URL to check.</p>
<p>
<asp:TextBox runat="server" ID="urlToCheck"></asp:TextBox>
<asp:Literal runat="server" ID="debugInfo"/>
</p>
</div>
<script runat="server">
protected override void OnInit(EventArgs arguments)
{
CheckSecurity(true);
}
protected void CheckSecurity(bool isDeveloperAllowed)
{
if (Sitecore.Context.User.IsAdministrator || (isDeveloperAllowed && this.IsDeveloper)) return;
var site = Sitecore.Context.Site;
if (site != null)
{
base.Response.Redirect(string.Format("{0}?returnUrl={1}", site.LoginPage, HttpUtility.UrlEncode(base.Request.Url.PathAndQuery)));
}
}
private bool IsDeveloper
{
get
{
return User.IsInRole(@"sitecore\developer") || User.IsInRole(@"sitecore\sitecore client developing");
}
}
protected void Page_Load(object sender, EventArgs e)
{
//var jobs = JobManager.GetJobs();
//repContent.DataSource = jobs;
//repContent.DataBind();
if (IsPostBack && !string.IsNullOrEmpty(urlToCheck.Text))
{
CheckUrl(urlToCheck.Text);
}
}
private void CheckUrl(string url)
{
try
{
WebClientGet(url, "GET");
debugInfo.Text = "Web Client GET success.<br/>";
WebClientPost(url, "POST");
debugInfo.Text += "Web Client POST success.<br/>";
}
catch (Exception ex)
{
debugInfo.Text = ex.ToString() + "</br>";
}
}
public string WebClientGet(string url, string method)
{
WebClient webClient = new WebClient();
byte[] responsebytes = webClient.DownloadData(url);
return Encoding.UTF8.GetString(responsebytes);
}
public string WebClientPost(string url, string method)
{
WebClient webClient = new WebClient();
byte[] responsebytes = webClient.UploadValues(url, "POST", new NameValueCollection());
return Encoding.UTF8.GetString(responsebytes);
}
</script>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment