MIME-Version: 1.0 Content-Location: file:///C:/09122912/HttpErrorManager.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii"
=
using System;
=
using
RemoteNet.Components.Utilities.Northrop.BOL;
=
using
RemoteNet.Components.Model.Northrop.BOL;
=
namespace
RemoteNet.Components.Utilities.Northrop.BOL
{
&n=
bsp; /// <summary>
&n=
bsp; /// Handles
various processing tasks on HttpError objects.
&n=
bsp; /// </summary>
&n=
bsp; /// <exception></exception>
&n=
bsp; ///<remarks>
&n=
bsp; /// <para></para>
&n=
bsp; /// <history>
&n=
bsp; /// =
<para>Created:
Tony Trivison . December 12, 2003</para>
&n=
bsp; /// =
<para>Modified:
</para>
&n=
bsp; /// </history>
&n=
bsp; ///</remarks>
&n=
bsp; public class HttpErrorManager
&n=
bsp; {
&n=
bsp;  =
; private HttpError
m_httpError;
&n=
bsp;  =
; private const string
MSG_INVALIDARG =3D "Invalid [item] data type. Must be of HttpError type.";
&n=
bsp;  =
; //***************************************************=
***********************************************
&n=
bsp;  =
; //Construction
&n=
bsp;  =
; //***************************************************=
***********************************************
&n=
bsp;  =
; /// <summary>
&n=
bsp;  =
; /// Initializes
a new instance of the HttpErrorManager class with the HttpError that it
contains.
&n=
bsp;  =
; /// </summary>
&n=
bsp;  =
; /// <exception></exception>
&n=
bsp;  =
; /// <param name=3D"pageError">The HttpError error that represents the error that oc=
curred.</param>
&n=
bsp;  =
; ///<remarks>
&n=
bsp;  =
; /// <para></para>
&n=
bsp;  =
; /// <history>
&n=
bsp;  =
; /// =
<para>Created:
Tony Trivison . December 12, 2003</para>
&n=
bsp;  =
; /// =
<para>Modified:
</para>
&n=
bsp;  =
; /// </history>
&n=
bsp;  =
; ///</remarks>
&n=
bsp;  =
; public
HttpErrorManager(HttpError pageError)
&n=
bsp;  =
; {
&n=
bsp;  =
; &n=
bsp; object item;
&n=
bsp;  =
; &n=
bsp;
&n=
bsp;  =
; &n=
bsp; item =3D pageError;
&n=
bsp;  =
; &n=
bsp; //Throw an exception if they pass it something that i=
sn't
of the HttpError type.
&n=
bsp;  =
; &n=
bsp; if(item.GetType() !=
=3D typeof(HttpError))
&n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; throw( new System.ArgumentException( MSG_INVALIDARG ) =
);
&n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; m_httpErr=
or
=3D pageError;
&n=
bsp;  =
; }
&n=
bsp;  =
; //***************************************************=
***********************************************
&n=
bsp;  =
; //Implementation
&n=
bsp;  =
; //***************************************************=
***********************************************
&n=
bsp;  =
; /// <summary>
&n=
bsp;  =
; /// Creates
an error number. TODO:implement functionality fo=
r this
method.
&n=
bsp;  =
; /// </summary>
&n=
bsp;  =
; /// <param name=3D"errorCode">The error code that represents the error sent to this=
page.</param>
&n=
bsp;  =
; /// <returns>Retu=
rns a
string that represents an error number.</r=
eturns>
&n=
bsp;  =
; /// <exception></exception>
&n=
bsp;  =
; ///<remarks>
&n=
bsp;  =
; /// <para>This nu=
mber can
be used for logging or research.</para>
&n=
bsp;  =
; /// <history>
&n=
bsp;  =
; /// =
<para>Created:
Tony Trivison . December 15, 2003</para>
&n=
bsp;  =
; /// =
<para>Modified:
</para>
&n=
bsp;  =
; /// </history>
&n=
bsp;  =
; ///</remarks>
&n=
bsp;  =
; public string GetErrorNumber(string
errorCode)
&n=
bsp;  =
; {
&n=
bsp;  =
; &n=
bsp; return errorCode;
&n=
bsp;  =
; }
&n=
bsp;  =
; ///****************=
***************************************************************************=
****************
&n=
bsp;  =
; /// <summary>
&n=
bsp;  =
; /// Determines
the header to use for the error Web page.
&n=
bsp;  =
; /// </summary>
&n=
bsp;  =
; /// <param name=3D"errorCode">The error code sent to the error.aspx page.</param>
&n=
bsp;  =
; /// <returns>Retu=
rns a
string that represents an error header.</r=
eturns>
&n=
bsp;  =
; /// <exception></exception>
&n=
bsp;  =
; ///<remarks>
&n=
bsp;  =
; /// <para>When an error occurs on th=
e site
and the visitor is redirected to the error.aspx.cs page,
&n=
bsp;  =
; /// a header is dis=
played
that corresponds with the error code.</para>
&n=
bsp;  =
; /// <history>
&n=
bsp;  =
; /// =
<para>Created:
Tony Trivison . December 9, 2003</para>
&n=
bsp;  =
; /// =
<para>Modified:
</para>
&n=
bsp;  =
; /// </history>
&n=
bsp;  =
; ///</remarks>
&n=
bsp;  =
; public string GetErrorPageHeader()
&n=
bsp;  =
; {
&n= bsp;  = ; &n= bsp; string errorHeader;<= o:p>
&n=
bsp;  =
; &n=
bsp; HttpError
myError =3D m_httpError;
&n=
bsp;  =
; &n=
bsp;
&n=
bsp;  =
; &n=
bsp; //Get the appropriate header message from the SiteSet=
tings
class,
&n=
bsp;  =
; &n=
bsp; //since we don't want to call web.config directly per=
our
model.
&n=
bsp;  =
; &n=
bsp; errorHeader =3D
SiteSettings.GetErrorHeader(myError.ErrorCode);
&n= bsp;  = ; &n= bsp; return errorHeader;<= o:p>
&n=
bsp;  =
; }
&n=
bsp;  =
; ///****************=
***************************************************************************=
****************
&n=
bsp;  =
; /// <summary>
&n=
bsp;  =
; /// Determines
the message to use for the error Web page.
&n=
bsp;  =
; /// </summary>
&n=
bsp;  =
; /// <param name=3D"errorCode">The error code sent to the error.aspx page.</param>
&n=
bsp;  =
; /// <returns>Retu=
rns a
string that represents an error message.</r=
eturns>
&n=
bsp;  =
; /// <exception></exception>
&n=
bsp;  =
; ///<remarks>
&n=
bsp;  =
; /// <para>When an error occurs on th=
e site
and the visitor is redirected to the error.aspx.cs page,
&n=
bsp;  =
; /// a message is di=
splayed
that corresponds with the error code.</para>
&n=
bsp;  =
; /// <history>
&n=
bsp;  =
; /// =
<para>Created:
Tony Trivison . December 9, 2003</para>
&n=
bsp;  =
; /// =
<para>Modified:
</para>
&n=
bsp;  =
; /// </history>
&n=
bsp;  =
; ///</remarks>
&n=
bsp;  =
; public string GetErrorPageMessage()
&n=
bsp;  =
; {
&n=
bsp;  =
; &n=
bsp; string errorMessage;=
&n=
bsp;  =
; &n=
bsp; HttpError
myError =3D m_httpError;
&n=
bsp;  =
; &n=
bsp; //Get the appropriate header message from the SiteSet=
tings
class,
&n=
bsp;  =
; &n=
bsp; //since we don't want to call web.config directly per=
our
model.
&n=
bsp;  =
; &n=
bsp; errorMessage =3D
SiteSettings.GetErrorMessage(myError.ErrorCode);
&n=
bsp;  =
; &n=
bsp; return errorMessage;=
&n=
bsp;  =
; }
&n=
bsp;  =
; //***************************************************=
***************************************************************************=
*
&n=
bsp;  =
; /// <summary>
&n=
bsp;  =
; /// Determines
whether or not the error warrants a notification.
&n=
bsp;  =
; /// </summary>
&n=
bsp;  =
; /// <param name=3D"errorCode">The error code that represents the error sent to this=
page.</param>
&n=
bsp;  =
; /// <param name=3D"IPAddress">The IPAddress of the site visitor=
.</p=
aram>
&n=
bsp;  =
; /// <param name=3D"referrer">The referrer page.</param>
&n=
bsp;  =
; /// <param name=3D"userAgent">The user agent of the site visitor.</p=
aram>
&n=
bsp;  =
; /// <param name=3D"queryString">
&n=
bsp;  =
; /// <returns>Retu=
rns true
or false depending on whether the error warrants a notification.</returns>
&n=
bsp;  =
; /// <exception></exception>
&n=
bsp;  =
; ///<remarks>
&n=
bsp;  =
; /// <para>We do not want an error
notification to be sent for all errors. If that were the case,
&n=
bsp;  =
; /// there would be =
too
many. The notification is typically an email that is sent to each
&n=
bsp;  =
; /// of
the developers.
&n=
bsp;  =
; /// TODO: Right now=
this
checks only for user agents.=
</para>
&n=
bsp;  =
; /// <history>
&n=
bsp;  =
; /// =
<para>Created:
Tony Trivison . December 11, 2003</para>
&n=
bsp;  =
; /// =
<para>Modified:
</para>
&n=
bsp;  =
; /// </history>
&n=
bsp;  =
; ///</remarks>
&n=
bsp;  =
; public bool IsErrorNotificationRequired()
&n=
bsp;  =
; {
&n= bsp;  = ; &n= bsp; string configValue;<= o:p>
&n=
bsp;  =
; &n=
bsp; string[] splitValues=
;
&n=
bsp;  =
; &n=
bsp; HttpError
myError =3D m_httpError;
&n=
bsp;  =
; &n=
bsp; string ipAddress;
&n=
bsp;  =
; &n=
bsp; string referrer;
&n=
bsp;  =
; &n=
bsp; string userAgent;
&n= bsp;  = ; &n= bsp; string queryString;<= o:p>
&n=
bsp;  =
; &n=
bsp; //***************************************************=
***************************************************
&n=
bsp;  =
; &n=
bsp; //User Agents
&n=
bsp;  =
; &n=
bsp; userAgent =3D myError.UserAgent;
&n=
bsp;  =
; &n=
bsp; //Get UserAgentsToIgnore from web=
.config
for this error code, going through the SiteSettings class.
&n=
bsp;  =
; &n=
bsp; configValue =3D
SiteSettings.UserAgentsToIgnoreByErrorCode(myError.ErrorCode);
&n=
bsp;  =
; &n=
bsp; //Parse the values that come back=
from
web.config.
&n=
bsp;  =
; &n=
bsp; splitValues =3D SiteFunctions.SplitValues(configValue)=
;
&n=
bsp;  =
; &n=
bsp; //If user agent is null make it an empty string.
&n=
bsp;  =
; &n=
bsp; //TODO: This could be cleaner and not do the check if=
it's
null.
&n=
bsp;  =
; &n=
bsp; if (userAgent =3D=3D=
null)
&n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; userAgent =3D "";
&n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; //If any of the values in the list match the user age=
nt
string, return false.
&n=
bsp;  =
; &n=
bsp; foreach (string s in
splitValues)
&n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; if (userAgent.ToLowe=
r() =3D=3D
s.ToLower())
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp;  =
; return false;
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; //***************************************************=
****************************************
&n=
bsp;  =
; &n=
bsp; //Query Strings
&n=
bsp;  =
; &n=
bsp; queryString =3D myError.QueryString;
&n=
bsp;  =
; &n=
bsp; //Get QueryStringsToIgnore from
web.config for this error code, going through the SiteSettings class.
&n=
bsp;  =
; &n=
bsp; configValue =3D
SiteSettings.QueryStringsToIgnoreByErrorCode(myError.ErrorCode);
&n=
bsp;  =
; &n=
bsp; //Parse the values that come back=
from
web.config.
&n=
bsp;  =
; &n=
bsp; splitValues =3D SiteFunctions.SplitValues(configValue)=
;
&n=
bsp;  =
; &n=
bsp; //If query string is null make it an empty string.
&n=
bsp;  =
; &n=
bsp; //TODO: This could be cleaner and not do the check if=
it's
null.
&n=
bsp;  =
; &n=
bsp; if (queryString =3D=
=3D null)
&n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; queryString =3D "";
&n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; //If any of the values in the list match the userAgent
string, return false.
&n=
bsp;  =
; &n=
bsp; foreach (string s in
splitValues)
&n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; if (queryString.ToLo=
wer() =3D=3D
s.ToLower())
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp;  =
; return false;
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; //***************************************************=
******************************************
&n=
bsp;  =
; &n=
bsp; //IP Addresses
&n=
bsp;  =
; &n=
bsp; ipAddress =3D myError.UserAddress;
&n=
bsp;  =
; &n=
bsp; //Get IPAddressesToIgnore from we=
b.config
for this error code, going through the SiteSettings class.
&n=
bsp;  =
; &n=
bsp; configValue =3D
SiteSettings.IPAddressesToIgnoreByErrorCode(myError.ErrorCode);
&n=
bsp;  =
; &n=
bsp; //Parse the values that come back=
from
web.config.
&n=
bsp;  =
; &n=
bsp; splitValues =3D SiteFunctions.SplitValues(configValue)=
;
&n=
bsp;  =
; &n=
bsp; //If IP Address is null make it an empty string.
&n=
bsp;  =
; &n=
bsp; //TODO: This could be cleaner and not do the check if=
it's
null.
&n=
bsp;  =
; &n=
bsp; if (ipAddress =3D=3D=
null)
&n=
bsp; &=
nbsp; &nbs=
p; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; ipAddress =3D "";
&n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; //If any of the values in the list match the IPAddres=
ses
string, return false.
&n=
bsp;  =
; &n=
bsp; foreach (string s in
splitValues)
&n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; if (ipAddress.ToLowe=
r() =3D=3D
s.ToLower())
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp;  =
; return false;
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; //***************************************************=
********************************************
&n=
bsp;  =
; &n=
bsp; //Referrers
&n=
bsp;  =
; &n=
bsp; referrer =3D myError.UrlReferrer;
&n=
bsp;  =
; &n=
bsp; //Get ReferrersToIgnore from web.=
config
for this error code, going through the SiteSettings class.
&n=
bsp;  =
; &n=
bsp; configValue =3D
SiteSettings.ReferrersToIgnoreByErrorCode(myError.ErrorCode);
&n=
bsp;  =
; &n=
bsp; //Parse the values that come back=
from
web.config.
&n=
bsp;  =
; &n=
bsp; splitValues =3D SiteFunctions.SplitValues(configValue)=
;
&n=
bsp;  =
; &n=
bsp; //If IP Address is null make it an empty string.
&n=
bsp;  =
; &n=
bsp; //TODO: This could be cleaner and not do the check if=
it's
null.
&n=
bsp;  =
; &n=
bsp; if (referrer =3D=3D =
null)
&n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; referrer =3D "";
&n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; //If any of the values in the list match the Referrers
string, return false.
&n=
bsp;  =
; &n=
bsp; foreach (string s in
splitValues)
&n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; if (referrer.ToLower=
() =3D=3D
s.ToLower())
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; {
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp;  =
; return false;
&n=
bsp;  =
; &n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; }
&n=
bsp;  =
; &n=
bsp; //end checking.
&n=
bsp;  =
; &n=
bsp; //***************************************************=
********************************************
&n=
bsp;  =
; &n=
bsp; //If no values in web.config match the value to check
against, return true to indicate to send
&n=
bsp;  =
; &n=
bsp; //a notification.
&n=
bsp;  =
; &n=
bsp; return true;
&n=
bsp;  =
; }
&n=
bsp; }
}