public override void Load() { if (base.Page.RequestValueCollection != null) { try { string requestViewStateString = base.Page.RequestViewStateString; string second = null; bool flag = false; if (!string.IsNullOrEmpty(requestViewStateString)) { Pair pair = (Pair) Util.DeserializeWithAssert(base.StateFormatter, requestViewStateString); if ((bool) pair.First) { second = (string) pair.Second; flag = true; } else { Pair pair2 = (Pair) pair.Second; second = (string) pair2.First; base.ControlState = pair2.Second; } } if (second != null) { object obj2 = base.Page.Session["__SESSIONVIEWSTATE" + second]; if (flag) { Pair pair3 = obj2 as Pair; if (pair3 != null) { base.ViewState = pair3.First; base.ControlState = pair3.Second; } } else { base.ViewState = obj2; } } } catch (Exception exception) { HttpException e = new HttpException(System.Web.SR.GetString("Invalid_ControlState"), exception); e.SetFormatter(new UseLastUnhandledErrorFormatter(e)); throw e; } } }
void IExecutionStep.Execute() { HttpContext context = _application.Context; IHttpHandler handler = context.Handler; if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.Page)) EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_ENTER, context.WorkerRequest); if (handler != null && HttpRuntime.UseIntegratedPipeline) { IIS7WorkerRequest wr = context.WorkerRequest as IIS7WorkerRequest; if (wr != null && wr.IsHandlerExecutionDenied()) { _sync = true; HttpException error = new HttpException(403, SR.GetString(SR.Handler_access_denied)); error.SetFormatter(new PageForbiddenErrorFormatter(context.Request.Path, SR.GetString(SR.Handler_access_denied))); throw error; } } if (handler == null) { _sync = true; } else if (handler is IHttpAsyncHandler) { // asynchronous handler IHttpAsyncHandler asyncHandler = (IHttpAsyncHandler)handler; _sync = false; _handler = asyncHandler; // Instrument the BeginProcessRequest method if AppVerifier is enabled. // If AppVerifier not enabled, we just get back the original delegate to BeginProcessRequest uninstrumented. var beginProcessRequestDelegate = AppVerifier.WrapBeginMethod<HttpContext>(_application, asyncHandler.BeginProcessRequest); _asyncStepCompletionInfo.Reset(); context.SyncContext.AllowVoidAsyncOperations(); IAsyncResult ar; try { ar = beginProcessRequestDelegate(context, _completionCallback, null); } catch { // The asynchronous step has completed, so we should disallow further // async operations until the next step. context.SyncContext.ProhibitVoidAsyncOperations(); throw; } bool operationCompleted; bool mustCallEndHandler; _asyncStepCompletionInfo.RegisterBeginUnwound(ar, out operationCompleted, out mustCallEndHandler); if (operationCompleted) { _sync = true; _handler = null; // not to remember // The asynchronous step has completed, so we should disallow further // async operations until the next step. context.SyncContext.ProhibitVoidAsyncOperations(); try { if (mustCallEndHandler) { asyncHandler.EndProcessRequest(ar); } _asyncStepCompletionInfo.ReportError(); } finally { SuppressPostEndRequestIfNecessary(context); // In Integrated mode, generate the necessary response headers // after the ASP.NET handler runs context.Response.GenerateResponseHeadersForHandler(); } if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.Page)) EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_LEAVE, context.WorkerRequest); } } else { // synchronous handler _sync = true; // disable async operations //_application.SyncContext.Disable(); // VSWhidbey 268772 - If a synchronous handler internally kicks off an asynchronous operation and waits (blocking) for that // operation to complete, the handler will deadlock since the asynchronous operation can't come back to the appropriate // thread to perform the completion. The solution below was only meant to be temporary but was accidentally left in the product // for v2.0 RTM, so it's now legacy behavior and cannot be changed. context.SyncContext.SetSyncCaller(); try { handler.ProcessRequest(context); } finally { context.SyncContext.ResetSyncCaller(); if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.Page)) EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_LEAVE, context.WorkerRequest); SuppressPostEndRequestIfNecessary(context); // In Integrated mode, generate the necessary response headers // after the ASP.NET handler runs context.Response.GenerateResponseHeadersForHandler(); } } }
internal IPartitionInfo CreatePartitionInfo(string sqlConnectionString) { /* * Parse the connection string for errors. We want to ensure * that the user's connection string doesn't contain an * Initial Catalog entry, so we must first create a dummy connection. */ SqlConnection dummyConnection; string attachDBFilename = null; try { dummyConnection = new SqlConnection(sqlConnectionString); } catch (Exception e) { if (s_usePartition) { HttpException outerException = new HttpException( SR.GetString(SR.Error_parsing_sql_partition_resolver_string, s_configPartitionResolverType, e.Message), e); outerException.SetFormatter(new UseLastUnhandledErrorFormatter(outerException)); throw outerException; } else { throw new ConfigurationErrorsException( SR.GetString(SR.Error_parsing_session_sqlConnectionString, e.Message), e, s_configSqlConnectionFileName, s_configSqlConnectionLineNumber); } } // Search for both Database and AttachDbFileName. Don't append our // database name if either of them exists. string database = dummyConnection.Database; SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder(sqlConnectionString); if (String.IsNullOrEmpty(database)) { database = scsb.AttachDBFilename; attachDBFilename = database; } if (!String.IsNullOrEmpty(database)) { if (!s_configAllowCustomSqlDatabase) { if (s_usePartition) { throw new HttpException( SR.GetString(SR.No_database_allowed_in_sql_partition_resolver_string, s_configPartitionResolverType, dummyConnection.DataSource, database)); } else { throw new ConfigurationErrorsException( SR.GetString(SR.No_database_allowed_in_sqlConnectionString), s_configSqlConnectionFileName, s_configSqlConnectionLineNumber); } } if (attachDBFilename != null) { HttpRuntime.CheckFilePermission(attachDBFilename, true); } } else { sqlConnectionString += ";Initial Catalog=ASPState"; } return new SqlPartitionInfo(new ResourcePool(new TimeSpan(0, 0, 5), int.MaxValue), scsb.IntegratedSecurity, sqlConnectionString); }
internal SqlStateConnection(SqlPartitionInfo sqlPartitionInfo, TimeSpan retryInterval) { Debug.Trace("SessionStateConnectionIdentity", "Connecting under " + WindowsIdentity.GetCurrent().Name); _partitionInfo = sqlPartitionInfo; _sqlConnection = new SqlConnection(sqlPartitionInfo.SqlConnectionString); bool isFirstAttempt = true; DateTime endRetryTime = DateTime.UtcNow; while(true) { try { _sqlConnection.Open(); // the operation succeeded, exit the loop if(!isFirstAttempt) { ClearFlagForClearPoolInProgress(); } break; } catch (SqlException e) { if (e != null && (e.Number == SQL_LOGIN_FAILED || e.Number == SQL_LOGIN_FAILED_2 || e.Number == SQL_LOGIN_FAILED_3)) { string user; SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder(sqlPartitionInfo.SqlConnectionString); if (scsb.IntegratedSecurity) { user = WindowsIdentity.GetCurrent().Name; } else { user = scsb.UserID; } HttpException outerException = new HttpException( SR.GetString(SR.Login_failed_sql_session_database, user ), e); outerException.SetFormatter(new UseLastUnhandledErrorFormatter(outerException)); ClearConnectionAndThrow(outerException); } if (!CanRetry(e, _sqlConnection, ref isFirstAttempt, ref endRetryTime)) { // just throw, the retry conditions are not satisfied ClearConnectionAndThrow(e); } } catch (Exception e) { // just throw, we have a different Exception ClearConnectionAndThrow(e); } } try { _partitionInfo.InitSqlInfo(_sqlConnection); Debug.Assert(sqlPartitionInfo.SupportFlags != SupportFlags.Uninitialized); PerfCounters.IncrementCounter(AppPerfCounter.SESSION_SQL_SERVER_CONNECTIONS); } catch { Dispose(); throw; } }
private static void ThrowError(Exception inner, string persistedState, string errorPageMessage, bool macValidationError) { ViewStateException innerException = new ViewStateException(inner, persistedState) { _macValidationError = macValidationError }; HttpException e = new HttpException(GetCorrectErrorPageMessage(innerException, errorPageMessage), innerException); e.SetFormatter(new UseLastUnhandledErrorFormatter(e)); throw e; }
void IHttpHandler.ProcessRequest(HttpContext context) { if (DeploymentSection.RetailInternal || (!context.Request.IsLocal && HttpRuntime.Profile.LocalOnly)) { HttpException exception = new HttpException(0x193, null); exception.SetFormatter(new TraceHandlerErrorFormatter(!DeploymentSection.RetailInternal)); throw exception; } this._context = context; this._response = this._context.Response; this._request = this._context.Request; this._writer = Page.CreateHtmlTextWriterInternal(this._response.Output, this._request); if (context.WorkerRequest is IIS7WorkerRequest) { this._response.ContentType = this._request.Browser.PreferredRenderingMime; } if (this._writer != null) { this._context.Trace.IsEnabled = false; this._request.ValidateInput(); this._writer.Write("<html>\r\n"); this._writer.Write("<head>\r\n"); this._writer.Write(StyleSheet); this._writer.Write("</head>\r\n"); this._writer.Write("<body>\r\n"); this._writer.Write("<span class=\"tracecontent\">\r\n"); if (!HttpRuntime.Profile.IsConfigEnabled) { HttpException exception2 = new HttpException(); exception2.SetFormatter(new TraceHandlerErrorFormatter(false)); throw exception2; } IList data = HttpRuntime.Profile.GetData(); if (this._request.QueryString["clear"] != null) { HttpRuntime.Profile.Reset(); string rawUrl = this._request.RawUrl; this._response.Redirect(rawUrl.Substring(0, rawUrl.IndexOf("?", StringComparison.Ordinal))); } string s = this._request.QueryString["id"]; if (s != null) { int num = int.Parse(s, CultureInfo.InvariantCulture); if ((num >= 0) && (num < data.Count)) { this.ShowDetails((DataSet) data[num]); this.ShowVersionDetails(); this._writer.Write("</span>\r\n</body>\r\n</html>\r\n"); return; } } this.ShowRequests(data); this.ShowVersionDetails(); this._writer.Write("</span>\r\n</body>\r\n</html>\r\n"); } }
private static void ThrowError(Exception inner, string persistedState, string errorPageMessage, bool macValidationError) { ViewStateException middle; HttpException outer; middle = new ViewStateException(inner, persistedState); middle._macValidationError = macValidationError; // Setup the formatter for this exception, to make sure this message shows up // in an error page as opposed to the inner-most exception's message. outer = new HttpException(GetCorrectErrorPageMessage(middle, errorPageMessage), middle); outer.SetFormatter(new UseLastUnhandledErrorFormatter(outer)); throw outer; }
internal void ReportRuntimeError(Exception e, bool canThrow, bool localExecute) { CustomErrorsSection customErrorsSetting = null; bool useCustomErrors = false; int code = -1; if (_completed) return; // always try to disable IIS custom errors when we send an error if (_wr != null) { _wr.TrySkipIisCustomErrors = true; } if (!localExecute) { code = HttpException.GetHttpCodeForException(e); // Don't raise event for 404. See VSWhidbey 124147. if (code != 404) { WebBaseEvent.RaiseRuntimeError(e, this); } // This cannot use the HttpContext.IsCustomErrorEnabled property, since it must call // GetSettings() with the canThrow parameter. customErrorsSetting = CustomErrorsSection.GetSettings(_context, canThrow); if (customErrorsSetting != null) useCustomErrors = customErrorsSetting.CustomErrorsEnabled(Request); else useCustomErrors = true; } if (!_headersWritten) { // nothing sent yet - entire response if (code == -1) { code = HttpException.GetHttpCodeForException(e); } // change 401 to 500 in case the config is not to impersonate if (code == 401 && !_context.IsClientImpersonationConfigured) code = 500; if (_context.TraceIsEnabled) _context.Trace.StatusCode = code; if (!localExecute && useCustomErrors) { String redirect = (customErrorsSetting != null) ? customErrorsSetting.GetRedirectString(code) : null; RedirectToErrorPageStatus redirectStatus = RedirectToErrorPage(redirect, customErrorsSetting.RedirectMode); switch (redirectStatus) { case RedirectToErrorPageStatus.Success: // success - nothing to do break; case RedirectToErrorPageStatus.NotAttempted: // if no redirect display generic error ClearAll(); StatusCode = code; WriteErrorMessage(e, dontShowSensitiveErrors: true); break; default: // DevDiv #70492 - If we tried to display the custom error page but failed in doing so, we should display // a generic error message instead of trying to display the original error. We have a compat switch on // the <customErrors> element to control this behavior. if (customErrorsSetting.AllowNestedErrors) { // The user has set the compat switch to use the original (pre-bug fix) behavior. goto case RedirectToErrorPageStatus.NotAttempted; } ClearAll(); StatusCode = 500; HttpException dummyException = new HttpException(); dummyException.SetFormatter(new CustomErrorFailedErrorFormatter()); WriteErrorMessage(dummyException, dontShowSensitiveErrors: true); break; } } else { ClearAll(); StatusCode = code; WriteErrorMessage(e, dontShowSensitiveErrors: false); } } else { Clear(); if (_contentType != null && _contentType.Equals("text/html")) { // in the middle of Html - break Html Write("\r\n\r\n</pre></table></table></table></table></table>"); Write("</font></font></font></font></font>"); Write("</i></i></i></i></i></b></b></b></b></b></u></u></u></u></u>"); Write("<p> </p><hr>\r\n\r\n"); } WriteErrorMessage(e, useCustomErrors); } }
private static void CreateMdfFile(string fullFileName, string dataDir, string connectionString) { bool flag = false; string database = null; HttpContext current = HttpContext.Current; string dbFileName = null; try { if (!Directory.Exists(dataDir)) { flag = true; Directory.CreateDirectory(dataDir); flag = false; try { if (current != null) { HttpRuntime.RestrictIISFolders(current); } } catch { } } fullFileName = fullFileName.ToUpper(CultureInfo.InvariantCulture); char[] chArray = Path.GetFileNameWithoutExtension(fullFileName).ToCharArray(); for (int i = 0; i < chArray.Length; i++) { if (!char.IsLetterOrDigit(chArray[i])) { chArray[i] = '_'; } } string str3 = new string(chArray); if (str3.Length > 30) { database = str3.Substring(0, 30) + "_" + Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); } else { database = str3 + "_" + Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); } dbFileName = Path.Combine(Path.GetDirectoryName(fullFileName), str3 + "_TMP.MDF"); SqlServices.Install(database, dbFileName, connectionString); DetachDB(database, connectionString); try { File.Move(dbFileName, fullFileName); } catch { if (!File.Exists(fullFileName)) { File.Copy(dbFileName, fullFileName); try { File.Delete(dbFileName); } catch { } } } try { File.Delete(dbFileName.Replace("_TMP.MDF", "_TMP_log.LDF")); } catch { } } catch (Exception exception) { if ((current == null) || current.IsCustomErrorEnabled) { throw; } HttpException exception2 = new HttpException(exception.Message, exception); if (exception is UnauthorizedAccessException) { exception2.SetFormatter(new SqlExpressConnectionErrorFormatter(flag ? DataConnectionErrorEnum.CanNotCreateDataDir : DataConnectionErrorEnum.CanNotWriteToDataDir)); } else { exception2.SetFormatter(new SqlExpressDBFileAutoCreationErrorFormatter(exception)); } throw exception2; } }
internal SqlStateConnection(SqlSessionStateStore.SqlPartitionInfo sqlPartitionInfo, TimeSpan retryInterval) { this._partitionInfo = sqlPartitionInfo; this._sqlConnection = new SqlConnection(sqlPartitionInfo.SqlConnectionString); bool isFirstAttempt = true; DateTime utcNow = DateTime.UtcNow; Label_0026: try { this._sqlConnection.Open(); if (!isFirstAttempt) { SqlSessionStateStore.ClearFlagForClearPoolInProgress(); } } catch (SqlException exception) { if ((exception != null) && (((exception.Number == 0x4818) || (exception.Number == 0x4814)) || (exception.Number == 0x4812))) { string name; SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(sqlPartitionInfo.SqlConnectionString); if (builder.IntegratedSecurity) { name = WindowsIdentity.GetCurrent().Name; } else { name = builder.UserID; } HttpException e = new HttpException(System.Web.SR.GetString("Login_failed_sql_session_database", new object[] { name }), exception); e.SetFormatter(new UseLastUnhandledErrorFormatter(e)); this.ClearConnectionAndThrow(e); } if (!SqlSessionStateStore.CanRetry(exception, this._sqlConnection, ref isFirstAttempt, ref utcNow)) { this.ClearConnectionAndThrow(exception); } goto Label_0026; } catch (Exception exception3) { this.ClearConnectionAndThrow(exception3); goto Label_0026; } try { this._partitionInfo.InitSqlInfo(this._sqlConnection); PerfCounters.IncrementCounter(AppPerfCounter.SESSION_SQL_SERVER_CONNECTIONS); } catch { this.Dispose(); throw; } }
internal static void EnsureTableIsRegisteredAndPolled(string database, string table) { DateTime time2; bool flag2; Exception exception; int num2; bool flag = false; if (HttpRuntime.CacheInternal[GetMoniterKey(database, table)] != null) { return; } InitPolling(database); DatabaseNotifState state = (DatabaseNotifState) s_DatabaseNotifStates[database]; if (!state._init) { int num; HttpContext current = HttpContext.Current; if (current == null) { num = 30; } else { num = Math.Max(current.Timeout.Seconds / 3, 30); } DateTime time = DateTime.UtcNow.Add(new TimeSpan(0, 0, num)); do { if (state._init) { goto Label_00BD; } Thread.Sleep(250); } while (Debugger.IsAttached || (DateTime.UtcNow <= time)); throw new HttpException(System.Web.SR.GetString("Cant_connect_sql_cache_dep_database_polling", new object[] { database })); } Label_00BD: num2 = 0; lock (state) { exception = state._pollExpt; if (exception != null) { num2 = state._pollSqlError; } time2 = state._utcTablesUpdated; flag2 = state._notifEnabled; } if (((exception == null) && flag2) && state._tables.ContainsKey(table)) { return; } if (flag || ((DateTime.UtcNow - time2) < OneSec)) { string str; if (num2 == 0xafc) { exception = null; } if (exception == null) { if (!flag2) { throw new DatabaseNotEnabledForNotificationException(System.Web.SR.GetString("Database_not_enabled_for_notification", new object[] { database })); } throw new TableNotEnabledForNotificationException(System.Web.SR.GetString("Table_not_enabled_for_notification", new object[] { table, database })); } switch (num2) { case 0xe5: case 0x106: str = "Permission_denied_database_polling"; break; default: str = "Cant_connect_sql_cache_dep_database_polling"; break; } HttpException e = new HttpException(System.Web.SR.GetString(str, new object[] { database }), exception); e.SetFormatter(new UseLastUnhandledErrorFormatter(e)); throw e; } UpdateDatabaseNotifState(database); flag = true; goto Label_00BD; }
internal IPartitionInfo CreatePartitionInfo(string sqlConnectionString) { SqlConnection connection; string path = null; try { connection = new SqlConnection(sqlConnectionString); } catch (Exception exception) { if (s_usePartition) { HttpException e = new HttpException(System.Web.SR.GetString("Error_parsing_sql_partition_resolver_string", new object[] { s_configPartitionResolverType, exception.Message }), exception); e.SetFormatter(new UseLastUnhandledErrorFormatter(e)); throw e; } throw new ConfigurationErrorsException(System.Web.SR.GetString("Error_parsing_session_sqlConnectionString", new object[] { exception.Message }), exception, s_configSqlConnectionFileName, s_configSqlConnectionLineNumber); } string database = connection.Database; SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(sqlConnectionString); if (string.IsNullOrEmpty(database)) { database = builder.AttachDBFilename; path = database; } if (!string.IsNullOrEmpty(database)) { if (!s_configAllowCustomSqlDatabase) { if (s_usePartition) { throw new HttpException(System.Web.SR.GetString("No_database_allowed_in_sql_partition_resolver_string", new object[] { s_configPartitionResolverType, connection.DataSource, database })); } throw new ConfigurationErrorsException(System.Web.SR.GetString("No_database_allowed_in_sqlConnectionString"), s_configSqlConnectionFileName, s_configSqlConnectionLineNumber); } if (path != null) { HttpRuntime.CheckFilePermission(path, true); } } else { sqlConnectionString = sqlConnectionString + ";Initial Catalog=ASPState"; } return new SqlPartitionInfo(new ResourcePool(new TimeSpan(0, 0, 5), 0x7fffffff), builder.IntegratedSecurity, sqlConnectionString); }
void IHttpHandler.ProcessRequest(HttpContext context) { // VSWhidbey 448844: Disable handler if retail is set to true if (DeploymentSection.RetailInternal || (!context.Request.IsLocal && HttpRuntime.Profile.LocalOnly)) { HttpException e = new HttpException(403, null); e.SetFormatter(new TraceHandlerErrorFormatter(!DeploymentSection.RetailInternal)); throw e; } _context = context; _response = _context.Response; _request = _context.Request; _writer = Page.CreateHtmlTextWriterInternal(_response.Output, _request); // if we're in integrated mode, we need to set the content type explicitly if (context.WorkerRequest is IIS7WorkerRequest) { _response.ContentType = _request.Browser.PreferredRenderingMime; } if (_writer == null) { // Can't create a writer, horked at this point, just return return; } _context.Trace.IsEnabled = false; // Validate the input to prevent XSS attacks. _request.ValidateInput(); _writer.Write("<html>\r\n"); _writer.Write("<head>\r\n"); _writer.Write(StyleSheet); _writer.Write("</head>\r\n"); _writer.Write("<body>\r\n"); _writer.Write("<span class=\"tracecontent\">\r\n"); if (!HttpRuntime.Profile.IsConfigEnabled) { HttpException e = new HttpException(); e.SetFormatter(new TraceHandlerErrorFormatter(false)); throw e; } IList datasets = HttpRuntime.Profile.GetData(); // first check if we should clear data if (_request.QueryString["clear"] != null) { HttpRuntime.Profile.Reset(); string url = _request.RawUrl; _response.Redirect(url.Substring(0, url.IndexOf("?", StringComparison.Ordinal))); } // then check if we are drilling down string strid = _request.QueryString["id"]; if (strid != null) { int index = Int32.Parse(strid, CultureInfo.InvariantCulture); if (index >=0 && index < datasets.Count) { ShowDetails((DataSet) datasets[index]); ShowVersionDetails(); _writer.Write("</span>\r\n</body>\r\n</html>\r\n"); return; } } // if we get here, its just generic request ShowRequests(datasets); ShowVersionDetails(); _writer.Write("</span>\r\n</body>\r\n</html>\r\n"); }
private static SqlCacheDependency CreateSql7SqlCacheDependencyForOutputCache(string database, string table, string depString) { SqlCacheDependency dependency; try { dependency = new SqlCacheDependency(database, table); } catch (HttpException exception) { HttpException e = new HttpException(System.Web.SR.GetString("Invalid_sqlDependency_argument2", new object[] { depString, exception.Message }), exception); e.SetFormatter(new UseLastUnhandledErrorFormatter(e)); throw e; } return dependency; }
void HttpApplication.IExecutionStep.Execute() { HttpContext context = this._application.Context; IHttpHandler handler = context.Handler; if (EtwTrace.IsTraceEnabled(4, 4)) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_ENTER, context.WorkerRequest); } if ((handler != null) && HttpRuntime.UseIntegratedPipeline) { IIS7WorkerRequest workerRequest = context.WorkerRequest as IIS7WorkerRequest; if ((workerRequest != null) && workerRequest.IsHandlerExecutionDenied()) { this._sync = true; HttpException exception = new HttpException(0x193, System.Web.SR.GetString("Handler_access_denied")); exception.SetFormatter(new PageForbiddenErrorFormatter(context.Request.Path, System.Web.SR.GetString("Handler_access_denied"))); throw exception; } } if (handler == null) { this._sync = true; } else if (handler is IHttpAsyncHandler) { IHttpAsyncHandler handler2 = (IHttpAsyncHandler) handler; this._sync = false; this._handler = handler2; IAsyncResult result = handler2.BeginProcessRequest(context, this._completionCallback, null); if (result.CompletedSynchronously) { this._sync = true; this._handler = null; try { handler2.EndProcessRequest(result); } finally { context.Response.GenerateResponseHeadersForHandler(); } if (EtwTrace.IsTraceEnabled(4, 4)) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_LEAVE, context.WorkerRequest); } } } else { this._sync = true; context.SyncContext.SetSyncCaller(); try { handler.ProcessRequest(context); } finally { context.SyncContext.ResetSyncCaller(); if (EtwTrace.IsTraceEnabled(4, 4)) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_HTTPHANDLER_LEAVE, context.WorkerRequest); } context.Response.GenerateResponseHeadersForHandler(); } } }
internal static void WriteValueToStream(object value, BinaryWriter writer) { if (value == null) { writer.Write((byte) 0x15); } else if (value is string) { writer.Write((byte) 1); writer.Write((string) value); } else if (value is int) { writer.Write((byte) 2); writer.Write((int) value); } else if (value is bool) { writer.Write((byte) 3); writer.Write((bool) value); } else if (value is DateTime) { writer.Write((byte) 4); DateTime time = (DateTime) value; writer.Write(time.Ticks); } else if (value is decimal) { writer.Write((byte) 5); int[] bits = decimal.GetBits((decimal) value); for (int i = 0; i < 4; i++) { writer.Write(bits[i]); } } else if (value is byte) { writer.Write((byte) 6); writer.Write((byte) value); } else if (value is char) { writer.Write((byte) 7); writer.Write((char) value); } else if (value is float) { writer.Write((byte) 8); writer.Write((float) value); } else if (value is double) { writer.Write((byte) 9); writer.Write((double) value); } else if (value is sbyte) { writer.Write((byte) 10); writer.Write((sbyte) value); } else if (value is short) { writer.Write((byte) 11); writer.Write((short) value); } else if (value is long) { writer.Write((byte) 12); writer.Write((long) value); } else if (value is ushort) { writer.Write((byte) 13); writer.Write((ushort) value); } else if (value is uint) { writer.Write((byte) 14); writer.Write((uint) value); } else if (value is ulong) { writer.Write((byte) 15); writer.Write((ulong) value); } else if (value is TimeSpan) { writer.Write((byte) 0x10); TimeSpan span = (TimeSpan) value; writer.Write(span.Ticks); } else if (value is Guid) { writer.Write((byte) 0x11); byte[] buffer = ((Guid) value).ToByteArray(); writer.Write(buffer); } else if (value is IntPtr) { writer.Write((byte) 0x12); IntPtr ptr = (IntPtr) value; if (IntPtr.Size == 4) { writer.Write(ptr.ToInt32()); } else { writer.Write(ptr.ToInt64()); } } else if (value is UIntPtr) { writer.Write((byte) 0x13); UIntPtr ptr2 = (UIntPtr) value; if (UIntPtr.Size == 4) { writer.Write(ptr2.ToUInt32()); } else { writer.Write(ptr2.ToUInt64()); } } else { writer.Write((byte) 20); BinaryFormatter formatter = new BinaryFormatter(); try { formatter.Serialize(writer.BaseStream, value); } catch (Exception exception) { HttpException e = new HttpException(System.Web.SR.GetString("Cant_serialize_session_state"), exception); e.SetFormatter(new UseLastUnhandledErrorFormatter(e)); throw e; } } }