diff --git a/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx b/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx
index aab8596..b5b3bbe 100644
--- a/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx
+++ b/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx
@@ -104,6 +104,16 @@
+
+
+
+
+
+
diff --git a/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx.cs b/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx.cs
index 99fca43..b12a733 100644
--- a/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx.cs
+++ b/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx.cs
@@ -29,74 +29,91 @@ protected void Page_Load(object sender, EventArgs e)
}
else
{
- Page.Validate();
- if (Page.IsValid)
+ try
{
- divFormGroup.Attributes["class"] = "form-group";
- divTable.Visible = true;
+ Page.Validate();
- var rewriter = new UrlRewriter();
- _db = Sitecore.Context.ContentDatabase;
+ if (Page.IsValid)
+ {
+ divFormGroup.Attributes["class"] = "form-group";
+ divTable.Visible = true;
- var rulesEngine = new RulesEngine();
- var inboundRules = rulesEngine.GetInboundRules(_db);
+ var rewriter = new UrlRewriter();
+ _db = Sitecore.Context.ContentDatabase;
- ProcessRequestResult results;
+ var rulesEngine = new RulesEngine();
+ var inboundRules = rulesEngine.GetInboundRules(_db);
- var requestUri = new Uri(txtUrl.Text);
- var siteContext = SiteContextFactory.GetSiteContext(requestUri.Host, requestUri.AbsolutePath,
- requestUri.Port);
+ ProcessRequestResult results;
- using (new SiteContextSwitcher(siteContext))
- using (new DatabaseSwitcher(_db))
- {
- results = rewriter.ProcessRequestUrl(new Uri(txtUrl.Text), inboundRules);
+ var requestUri = new Uri(txtUrl.Text);
+ var siteContext = SiteContextFactory.GetSiteContext(requestUri.Host, requestUri.AbsolutePath,
+ requestUri.Port);
- }
+ using (new SiteContextSwitcher(siteContext))
+ using (new DatabaseSwitcher(_db))
+ {
+ results = rewriter.ProcessRequestUrl(new Uri(txtUrl.Text), inboundRules);
- if (results == null)
- {
- return;
- }
+ }
+
+ if (results == null)
+ {
+ divTable.Visible = false;
+ divInfo.Visible = true;
+ divInfo.InnerText = "Sorry, I couldn't find any rules to process. :(";
+ return;
+ }
- resultsRepeater.DataSource = results.ProcessedResults;
- resultsRepeater.DataBind();
+ resultsRepeater.DataSource = results.ProcessedResults;
+ resultsRepeater.DataBind();
- var isAbort = results.FinalAction is AbortRequestAction;
- var isCustomResponse = results.FinalAction is CustomResponseAction;
+ var isAbort = results.FinalAction is AbortRequestAction;
+ var isCustomResponse = results.FinalAction is CustomResponseAction;
- if (isAbort)
- {
- txtFinalUrl.InnerText = "Aborted";
- }
- else if (isCustomResponse)
- {
- var customResponse = results.FinalAction as CustomResponseAction;
- const string resultFormat = "Custom Response: {0} {1} {2}";
- txtFinalUrl.InnerText = string.Format(resultFormat, customResponse.StatusCode,
- customResponse.SubStatusCode, customResponse.ErrorDescription);
- }
- else
- {
- if (!results.MatchedAtLeastOneRule)
+ if (isAbort)
{
- txtFinalUrl.InnerText = "No matches.";
+ txtFinalUrl.InnerText = "Aborted";
+ }
+ else if (isCustomResponse)
+ {
+ var customResponse = results.FinalAction as CustomResponseAction;
+ const string resultFormat = "Custom Response: {0} {1} {2}";
+ txtFinalUrl.InnerText = string.Format(resultFormat, customResponse.StatusCode,
+ customResponse.SubStatusCode, customResponse.ErrorDescription);
}
else
{
- const string resultFormat = "Redirected to {0}.";
- txtFinalUrl.InnerText = string.Format(resultFormat, results.RewrittenUri.ToString());
+ if (!results.MatchedAtLeastOneRule)
+ {
+ txtFinalUrl.InnerText = "No matches.";
+ }
+ else
+ {
+ const string resultFormat = "Redirected to {0}.";
+ txtFinalUrl.InnerText = string.Format(resultFormat, results.RewrittenUri.ToString());
+ }
}
}
- }
- else
- {
- if (!vldTxtUrl.IsValid)
+ else
{
- divFormGroup.Attributes["class"] = "form-group has-error";
+ if (!vldTxtUrl.IsValid)
+ {
+ divFormGroup.Attributes["class"] = "form-group has-error";
+ }
}
}
+ catch (Exception ex)
+ {
+ divTable.Visible = false;
+ divInfo.Visible = false;
+ divError.Visible = true;
+ txtError.InnerText = @"Exception:
+
+ " + ex.Message;
+ }
+
}
}
diff --git a/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx.designer.cs b/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx.designer.cs
index bdd4010..f94cc28 100644
--- a/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx.designer.cs
+++ b/Hi.UrlRewrite/sitecore modules/Shell/UrlRewrite/Default.aspx.designer.cs
@@ -83,5 +83,32 @@ public partial class Default {
/// To modify move field declaration from designer file to code-behind file.
///
protected global::System.Web.UI.HtmlControls.HtmlGenericControl txtFinalUrl;
+
+ ///
+ /// divInfo control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.HtmlControls.HtmlGenericControl divInfo;
+
+ ///
+ /// divError control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.HtmlControls.HtmlGenericControl divError;
+
+ ///
+ /// txtError control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.HtmlControls.HtmlGenericControl txtError;
}
}