using System.Security.Principal;
using System.Threading;
using System.Web.Caching;
+using System.Web.Compilation;
using System.Web.Configuration;
+using System.Web.Management;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.Util;
public HttpRequest Request {
get {
if (context == null)
- throw new HttpException (Locale.GetText ("No context is available."));
+ throw HttpException.NewWithCode (Locale.GetText ("No context is available."), WebEventCodes.RuntimeErrorRequestAbort);
if (false == HttpApplicationFactory.ContextAvailable)
- throw new HttpException (Locale.GetText ("Request is not available in this context."));
+ throw HttpException.NewWithCode (Locale.GetText ("Request is not available in this context."), WebEventCodes.RuntimeErrorRequestAbort);
return context.Request;
}
public HttpResponse Response {
get {
if (context == null)
- throw new HttpException (Locale.GetText ("No context is available."));
+ throw HttpException.NewWithCode (Locale.GetText ("No context is available."), WebEventCodes.RuntimeErrorRequestAbort);
if (false == HttpApplicationFactory.ContextAvailable)
- throw new HttpException (Locale.GetText ("Response is not available in this context."));
+ throw HttpException.NewWithCode (Locale.GetText ("Response is not available in this context."), WebEventCodes.RuntimeErrorRequestAbort);
return context.Response;
}
return session;
if (context == null)
- throw new HttpException (Locale.GetText ("No context is available."));
+ throw HttpException.NewWithCode (Locale.GetText ("No context is available."), WebEventCodes.RuntimeErrorRequestAbort);
HttpSessionState ret = context.Session;
if (ret == null)
- throw new HttpException (Locale.GetText ("Session state is not available in the context."));
+ throw HttpException.NewWithCode (Locale.GetText ("Session state is not available in the context."), WebEventCodes.RuntimeErrorRequestAbort);
return ret;
}
return null;
}
+ bool ShouldHandleException (Exception e)
+ {
+ if (e is ParseException)
+ return false;
+
+ return true;
+ }
+
//
// If we catch an error, queue this error
//
{
bool first = context.Error == null;
context.AddError (e);
- if (first) {
+ if (first && ShouldHandleException (e)) {
EventHandler eh = nonApplicationEvents [errorEvent] as EventHandler;
if (eh != null){
try {
eh (this, EventArgs.Empty);
+ if (stop_processing)
+ context.ClearError ();
} catch (ThreadAbortException taex){
context.ClearError ();
- if (FlagEnd.Value == taex.ExceptionState)
- // This happens on Redirect() or End()
+ if (FlagEnd.Value == taex.ExceptionState || HttpRuntime.DomainUnloading)
+ // This happens on Redirect(), End() and
+ // when unloading the AppDomain
Thread.ResetAbort ();
else
// This happens on Thread.Abort()
} catch (ThreadAbortException taex) {
object obj = taex.ExceptionState;
Thread.ResetAbort ();
- stop_processing = true;
if (obj is StepTimeout)
- ProcessError (new HttpException ("The request timed out."));
+ ProcessError (HttpException.NewWithCode ("The request timed out.", WebEventCodes.RequestTransactionAbort));
else {
context.ClearError ();
- if (FlagEnd.Value != obj)
+ if (FlagEnd.Value != obj && !HttpRuntime.DomainUnloading)
context.AddError (taex);
}
-
+
+ stop_processing = true;
PipelineDone ();
} catch (Exception e) {
- stop_processing = true;
ProcessError (e);
+ stop_processing = true;
PipelineDone ();
}
}
if (error is HttpException){
response.StatusCode = ((HttpException)error).GetHttpCode ();
} else {
- error = new HttpException ("", error);
+ error = HttpException.NewWithCode (String.Empty, error, WebEventCodes.WebErrorOtherError);
response.StatusCode = 500;
}
HttpException httpEx = (HttpException) error;
response.Flush (true);
} else {
if (!(error is HttpException))
- error = new HttpException ("", error);
+ error = HttpException.NewWithCode (String.Empty, error, WebEventCodes.WebErrorOtherError);
FinalErrorWrite (response, ((HttpException) error).GetHtmlErrorMessage ());
}
}
if (stop_processing)
yield return true;
+#if NET_4_0
+ if (HttpRequest.ValidateRequestNewMode) {
+ char[] invalidChars = HttpRequest.RequestPathInvalidCharacters;
+ HttpRequest req = context.Request;
+ if (invalidChars != null && req != null) {
+ string path = req.PathNoValidation;
+ int idx = path != null ? path.IndexOfAny (invalidChars) : -1;
+ if (idx != -1)
+ throw HttpException.NewWithCode (
+ String.Format ("A potentially dangerous Request.Path value was detected from the client ({0}).", path [idx]),
+ WebEventCodes.RuntimeErrorValidationFailure
+ );
+ }
+ }
+#endif
context.MapRequestHandlerDone = false;
StartTimer ("BeginRequest");
eventHandler = Events [BeginRequestEvent];
Console.WriteLine (fnf.ToString ());
#endif
if (context.Request.IsLocal)
- ProcessError (new HttpException (404, String.Format ("File not found {0}", fnf.FileName), fnf, context.Request.FilePath));
+ ProcessError (HttpException.NewWithCode (404,
+ String.Format ("File not found {0}", fnf.FileName),
+ fnf,
+ context.Request.FilePath,
+ WebEventCodes.RuntimeErrorRequestAbort));
else
- ProcessError (new HttpException (404, "File not found: " + Path.GetFileName (fnf.FileName), context.Request.FilePath));
+ ProcessError (HttpException.NewWithCode (404,
+ "File not found: " + Path.GetFileName (fnf.FileName),
+ context.Request.FilePath,
+ WebEventCodes.RuntimeErrorRequestAbort));
} catch (DirectoryNotFoundException dnf){
if (!context.Request.IsLocal)
dnf = null; // Do not "leak" real path information
- ProcessError (new HttpException (404, "Directory not found", dnf));
+ ProcessError (HttpException.NewWithCode (404, "Directory not found", dnf, WebEventCodes.RuntimeErrorRequestAbort));
} catch (Exception e) {
ProcessError (e);
}
InitOnce (true);
} catch (Exception e) {
initialization_exception = e;
- FinalErrorWrite (context.Response, new HttpException ("", e).GetHtmlErrorMessage ());
+ FinalErrorWrite (context.Response, HttpException.NewWithCode (String.Empty, e, WebEventCodes.RuntimeErrorRequestAbort).GetHtmlErrorMessage ());
PipelineDone ();
return;
}
return RedirectErrorPage (redirect);
}
catch (Exception ex) {
- httpEx = new HttpException (500, "", ex);
+ httpEx = HttpException.NewWithCode (500, String.Empty, ex, WebEventCodes.WebErrorOtherError);
return false;
}
}
return null;
}
+ internal static Type LoadType <TBaseType> (string typeName, bool throwOnMissing)
+ {
+ Type ret = LoadType (typeName, throwOnMissing);
+
+ if (typeof (TBaseType).IsAssignableFrom (ret))
+ return ret;
+
+ if (throwOnMissing)
+ throw new TypeLoadException (String.Format ("Type '{0}' found but it doesn't derive from base type '{1}'.", typeName, typeof (TBaseType)));
+
+ return null;
+ }
+
internal static Type LoadTypeFromBin (string typeName)
{
Type type = null;