wsp-10212 fixed: option set deatiled error mode on web site

This commit is contained in:
Ruslan Keba 2013-11-08 12:34:33 +02:00
parent 0a16e252c9
commit aa4db51dd5
7 changed files with 133 additions and 34 deletions

View file

@ -34,8 +34,25 @@ using System.ComponentModel;
namespace WebsitePanel.Providers.Web namespace WebsitePanel.Providers.Web
{ {
public class HttpError public enum HttpErrorsMode
{ {
DetailedLocalOnly = 0,
Custom = 1,
Detailed = 2
}
public enum HttpErrorsExistingResponse
{
Auto = 0,
Replace = 1,
PassThrough = 2
}
public class HttpError
{
public const HttpErrorsMode DefaultHttpErrorsMode = HttpErrorsMode.DetailedLocalOnly;
public const HttpErrorsExistingResponse DefaultHttpErrorsExistingResponse = HttpErrorsExistingResponse.Auto;
private string errorCode; private string errorCode;
private string errorSubcode; private string errorSubcode;
private string handlerType; private string handlerType;

View file

@ -61,6 +61,8 @@ namespace WebsitePanel.Providers.Web
private string defaultDocs; private string defaultDocs;
private string httpRedirect; private string httpRedirect;
private HttpError[] httpErrors; private HttpError[] httpErrors;
private HttpErrorsMode errorMode;
private HttpErrorsExistingResponse existingResponse;
private MimeMap[] mimeMaps; private MimeMap[] mimeMaps;
private HttpHeader[] httpHeaders; private HttpHeader[] httpHeaders;
private bool aspInstalled; private bool aspInstalled;
@ -122,6 +124,18 @@ namespace WebsitePanel.Providers.Web
set { httpErrors = value; } set { httpErrors = value; }
} }
public HttpErrorsMode ErrorMode
{
get { return errorMode; }
set { errorMode = value; }
}
public HttpErrorsExistingResponse ExistingResponse
{
get { return existingResponse; }
set { existingResponse = value; }
}
public string ApplicationPool public string ApplicationPool
{ {
get { return this.applicationPool; } get { return this.applicationPool; }

View file

@ -54,6 +54,9 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects
var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath); var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath);
// //
var httpErrorsSection = config.GetSection(Constants.HttpErrorsSection); var httpErrorsSection = config.GetSection(Constants.HttpErrorsSection);
virtualDir.ErrorMode = (HttpErrorsMode)httpErrorsSection.GetAttributeValue("errorMode");
virtualDir.ExistingResponse = (HttpErrorsExistingResponse)httpErrorsSection.GetAttributeValue("existingResponse");
// //
var errorsCollection = httpErrorsSection.GetCollection(); var errorsCollection = httpErrorsSection.GetCollection();
// //
@ -87,10 +90,6 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects
} }
#endregion #endregion
// Http errors list is either empty or not set so defaults to the parent
if (virtualDir.HttpErrors == null || virtualDir.HttpErrors.Length == 0)
return;
#region Put the change in effect #region Put the change in effect
using (var srvman = GetServerManager()) using (var srvman = GetServerManager())
{ {
@ -98,33 +97,45 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects
// //
var section = config.GetSection(Constants.HttpErrorsSection); var section = config.GetSection(Constants.HttpErrorsSection);
// enable custom errors // set error mode
section.SetAttributeValue("errorMode", "Custom"); section.SetAttributeValue("errorMode", virtualDir.ErrorMode);
if (virtualDir.ErrorMode == HttpErrorsMode.Detailed)
{
section.SetAttributeValue("existingResponse", HttpErrorsExistingResponse.PassThrough);
}
else
{
section.SetAttributeValue("existingResponse", HttpErrorsExistingResponse.Auto);
}
// // save custom errors
var errorsCollection = section.GetCollection(); if (virtualDir.HttpErrors != null && virtualDir.HttpErrors.Length > 0)
// {
foreach (var item in virtualDir.HttpErrors) var errorsCollection = section.GetCollection();
{ //
int indexOf = FindHttpError(errorsCollection, item); foreach (var item in virtualDir.HttpErrors)
// Just update the element attributes - IIS 7 API will do the rest {
if (indexOf > -1) int indexOf = FindHttpError(errorsCollection, item);
{ // Just update the element attributes - IIS 7 API will do the rest
var item2Renew = errorsCollection[indexOf]; if (indexOf > -1)
// {
FillConfigurationElementWithData(item2Renew, item, virtualDir); var item2Renew = errorsCollection[indexOf];
// //
continue; FillConfigurationElementWithData(item2Renew, item, virtualDir);
} //
// continue;
var item2Add = CreateHttpError(errorsCollection, item, virtualDir); }
// //
if (item2Add == null) var item2Add = CreateHttpError(errorsCollection, item, virtualDir);
continue; //
// if (item2Add == null)
errorsCollection.Add(item2Add); continue;
} //
// errorsCollection.Add(item2Add);
}
}
//
srvman.CommitChanges(); srvman.CommitChanges();
} }
#endregion #endregion

View file

@ -156,4 +156,7 @@
<data name="IIS7.Redirect" xml:space="preserve"> <data name="IIS7.Redirect" xml:space="preserve">
<value>Redirect</value> <value>Redirect</value>
</data> </data>
<data name="lblErrorMode.Text">
<value xml:space="preserve">Error Mode</value>
</data>
</root> </root>

View file

@ -1,4 +1,19 @@
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebSitesCustomErrorsControl.ascx.cs" Inherits="WebsitePanel.Portal.WebSitesCustomErrorsControl" %> <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebSitesCustomErrorsControl.ascx.cs" Inherits="WebsitePanel.Portal.WebSitesCustomErrorsControl" %>
<div style="padding: 20; margin-bottom: 10px;">
<table cellpadding="4">
<tr id="rowAspNet" runat="server">
<td class="SubHead">
<asp:Label ID="lblErrorMode" runat="server" meta:resourcekey="lblErrorMode"></asp:Label>:
</td>
<td class="Normal">
<asp:DropDownList ID="ddlErrorMode" runat="server" CssClass="NormalTextBox"></asp:DropDownList>
</td>
</tr>
</table>
</div>
<div class="FormButtonsBar"> <div class="FormButtonsBar">
<asp:Button id="btnAdd" runat="server" meta:resourcekey="btnAddError" Text="Add Custom Error" CssClass="Button3" OnClick="btnAdd_Click" CausesValidation="False"></asp:Button> <asp:Button id="btnAdd" runat="server" meta:resourcekey="btnAddError" Text="Add Custom Error" CssClass="Button3" OnClick="btnAdd_Click" CausesValidation="False"></asp:Button>
</div> </div>

View file

@ -63,16 +63,29 @@ namespace WebsitePanel.Portal
{ {
IIs7 = item.IIs7; IIs7 = item.IIs7;
// bind data // bind error mode
ddlErrorMode.Items.Add(HttpErrorsMode.DetailedLocalOnly.ToString());
ddlErrorMode.Items.Add(HttpErrorsMode.Custom.ToString());
ddlErrorMode.Items.Add(HttpErrorsMode.Detailed.ToString());
ddlErrorMode.SelectedValue = item.ErrorMode.ToString();
// bind errors list
gvErrorPages.DataSource = item.HttpErrors; gvErrorPages.DataSource = item.HttpErrors;
gvErrorPages.DataBind(); gvErrorPages.DataBind();
} }
public void SaveWebItem(WebVirtualDirectory item) public void SaveWebItem(WebVirtualDirectory item)
{ {
item.ErrorMode = GetSelectedErrorMode();
item.HttpErrors = CollectFormData(false).ToArray(); item.HttpErrors = CollectFormData(false).ToArray();
} }
private HttpErrorsMode GetSelectedErrorMode()
{
return (HttpErrorsMode)Enum.Parse(typeof (HttpErrorsMode), ddlErrorMode.SelectedValue);
}
public List<HttpError> CollectFormData(bool includeEmpty) public List<HttpError> CollectFormData(bool includeEmpty)
{ {
List<HttpError> errors = new List<HttpError>(); List<HttpError> errors = new List<HttpError>();

View file

@ -1,10 +1,9 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
// Runtime Version:2.0.50727.3074
// //
// Changes to this file may cause incorrect behavior and will be lost if // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -13,6 +12,33 @@ namespace WebsitePanel.Portal {
public partial class WebSitesCustomErrorsControl { public partial class WebSitesCustomErrorsControl {
/// <summary>
/// rowAspNet control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlTableRow rowAspNet;
/// <summary>
/// lblErrorMode control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label lblErrorMode;
/// <summary>
/// ddlErrorMode control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.DropDownList ddlErrorMode;
/// <summary> /// <summary>
/// btnAdd control. /// btnAdd control.
/// </summary> /// </summary>