Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / xsp / System / Web / Hosting / ISAPIRuntime.cs / 6 / ISAPIRuntime.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* The ASP.NET runtime services
*
* Copyright (c) 1998 Microsoft Corporation
*/
namespace System.Web.Hosting {
using System.Runtime.InteropServices;
using System.Collections;
using System.Reflection;
using System.Threading;
using System.Web;
using System.Web.Management;
using System.Web.Util;
using System.Globalization;
using System.Security.Permissions;
///
/// [To be supplied.]
///
///
// NOTE: There is no link demand here because it causes a 7% perf regression.
// there is a Demand on the .ctor for ISAPIRuntime, which provides the same level of
// security, except that we only take a one time perf hit when an instance is created.
[ComImport, Guid("08a2c56f-7c16-41c1-a8be-432917a1a2d1"), System.Runtime.InteropServices.InterfaceTypeAttribute(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIUnknown)]
public interface IISAPIRuntime {
///
/// [To be supplied.]
///
void StartProcessing();
///
/// [To be supplied.]
///
void StopProcessing();
///
/// [To be supplied.]
///
[return: MarshalAs(UnmanagedType.I4)]
int ProcessRequest(
[In]
IntPtr ecb,
[In, MarshalAs(UnmanagedType.I4)]
int useProcessModel);
///
/// [To be supplied.]
///
void DoGCCollect();
}
///
/// [To be supplied.]
///
///
// NOTE: There is no link demand here because it causes a 7% perf regression.
// there is a Demand on the .ctor for ISAPIRuntime, which provides the same level of
// security, except that we only take a one time perf hit when an instance is created.
public sealed class ISAPIRuntime : MarshalByRefObject, IISAPIRuntime, IRegisteredObject {
// WARNING: do not modify without making corresponding changes in appdomains.h
private const int WORKER_REQUEST_TYPE_IN_PROC = 0x0;
private const int WORKER_REQUEST_TYPE_OOP = 0x1;
private const int WORKER_REQUEST_TYPE_IN_PROC_VERSION_2 = 0x2;
// to control removal from unmanaged table (to it only once)
private static int _isThisAppDomainRemovedFromUnmanagedTable;
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public ISAPIRuntime() {
HostingEnvironment.RegisterObject(this);
}
public override Object InitializeLifetimeService() {
return null; // never expire lease
}
///
/// [To be supplied.]
///
public void StartProcessing() {
Debug.Trace("ISAPIRuntime", "StartProcessing");
}
///
/// [To be supplied.]
///
public void StopProcessing() {
Debug.Trace("ISAPIRuntime", "StopProcessing");
HostingEnvironment.UnregisterObject(this);
}
/*
* Process one ISAPI request
*
* @param ecb ECB
* @param useProcessModel flag set to true when out-of-process
*/
///
/// [To be supplied.]
///
public int ProcessRequest(IntPtr ecb, int iWRType) {
IntPtr pHttpCompletion = IntPtr.Zero;
if (iWRType == WORKER_REQUEST_TYPE_IN_PROC_VERSION_2) {
pHttpCompletion = ecb;
ecb = UnsafeNativeMethods.GetEcb(pHttpCompletion);
}
ISAPIWorkerRequest wr = null;
try {
bool useOOP = (iWRType == WORKER_REQUEST_TYPE_OOP);
wr = ISAPIWorkerRequest.CreateWorkerRequest(ecb, useOOP);
wr.Initialize();
// check if app path matches (need to restart app domain?)
String wrPath = wr.GetAppPathTranslated();
String adPath = HttpRuntime.AppDomainAppPathInternal;
if (adPath == null ||
StringUtil.EqualsIgnoreCase(wrPath, adPath)) {
HttpRuntime.ProcessRequestNoDemand(wr);
return 0;
}
else {
// need to restart app domain
HttpRuntime.ShutdownAppDomain(ApplicationShutdownReason.PhysicalApplicationPathChanged,
SR.GetString(SR.Hosting_Phys_Path_Changed,
adPath,
wrPath));
return 1;
}
}
catch(Exception e) {
try {
WebBaseEvent.RaiseRuntimeError(e, this);
} catch {}
// Have we called HSE_REQ_DONE_WITH_SESSION? If so, don't re-throw.
if (wr != null && wr.Ecb == IntPtr.Zero) {
if (pHttpCompletion != IntPtr.Zero) {
UnsafeNativeMethods.SetDoneWithSessionCalled(pHttpCompletion);
}
// if this is a thread abort exception, cancel the abort
if (e is ThreadAbortException) {
Thread.ResetAbort();
}
// IMPORTANT: if this thread is being aborted because of an AppDomain.Unload,
// the CLR will still throw an AppDomainUnloadedException. The native caller
// must special case COR_E_APPDOMAINUNLOADED(0x80131014) and not
// call HSE_REQ_DONE_WITH_SESSION more than once.
return 0;
}
// re-throw if we have not called HSE_REQ_DONE_WITH_SESSION
throw;
}
}
///
/// [To be supplied.]
///
public void DoGCCollect() {
for (int c = 10; c > 0; c--) {
System.GC.Collect();
}
}
///
void IRegisteredObject.Stop(bool immediate) {
RemoveThisAppDomainFromUnmanagedTable();
HostingEnvironment.UnregisterObject(this);
}
internal static void RemoveThisAppDomainFromUnmanagedTable() {
if (Interlocked.Exchange(ref _isThisAppDomainRemovedFromUnmanagedTable, 1) != 0) {
return;
}
try {
String appId = HttpRuntime.AppDomainAppIdInternal;
if (appId != null ) {
Debug.Trace("ISAPIRuntime", "Calling UnsafeNativeMethods.AppDomainRestart appId=" + appId);
UnsafeNativeMethods.AppDomainRestart(appId);
}
HttpRuntime.AddAppDomainTraceMessage(SR.GetString(SR.App_Domain_Restart));
}
catch {
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* The ASP.NET runtime services
*
* Copyright (c) 1998 Microsoft Corporation
*/
namespace System.Web.Hosting {
using System.Runtime.InteropServices;
using System.Collections;
using System.Reflection;
using System.Threading;
using System.Web;
using System.Web.Management;
using System.Web.Util;
using System.Globalization;
using System.Security.Permissions;
///
/// [To be supplied.]
///
///
// NOTE: There is no link demand here because it causes a 7% perf regression.
// there is a Demand on the .ctor for ISAPIRuntime, which provides the same level of
// security, except that we only take a one time perf hit when an instance is created.
[ComImport, Guid("08a2c56f-7c16-41c1-a8be-432917a1a2d1"), System.Runtime.InteropServices.InterfaceTypeAttribute(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIUnknown)]
public interface IISAPIRuntime {
///
/// [To be supplied.]
///
void StartProcessing();
///
/// [To be supplied.]
///
void StopProcessing();
///
/// [To be supplied.]
///
[return: MarshalAs(UnmanagedType.I4)]
int ProcessRequest(
[In]
IntPtr ecb,
[In, MarshalAs(UnmanagedType.I4)]
int useProcessModel);
///
/// [To be supplied.]
///
void DoGCCollect();
}
///
/// [To be supplied.]
///
///
// NOTE: There is no link demand here because it causes a 7% perf regression.
// there is a Demand on the .ctor for ISAPIRuntime, which provides the same level of
// security, except that we only take a one time perf hit when an instance is created.
public sealed class ISAPIRuntime : MarshalByRefObject, IISAPIRuntime, IRegisteredObject {
// WARNING: do not modify without making corresponding changes in appdomains.h
private const int WORKER_REQUEST_TYPE_IN_PROC = 0x0;
private const int WORKER_REQUEST_TYPE_OOP = 0x1;
private const int WORKER_REQUEST_TYPE_IN_PROC_VERSION_2 = 0x2;
// to control removal from unmanaged table (to it only once)
private static int _isThisAppDomainRemovedFromUnmanagedTable;
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public ISAPIRuntime() {
HostingEnvironment.RegisterObject(this);
}
public override Object InitializeLifetimeService() {
return null; // never expire lease
}
///
/// [To be supplied.]
///
public void StartProcessing() {
Debug.Trace("ISAPIRuntime", "StartProcessing");
}
///
/// [To be supplied.]
///
public void StopProcessing() {
Debug.Trace("ISAPIRuntime", "StopProcessing");
HostingEnvironment.UnregisterObject(this);
}
/*
* Process one ISAPI request
*
* @param ecb ECB
* @param useProcessModel flag set to true when out-of-process
*/
///
/// [To be supplied.]
///
public int ProcessRequest(IntPtr ecb, int iWRType) {
IntPtr pHttpCompletion = IntPtr.Zero;
if (iWRType == WORKER_REQUEST_TYPE_IN_PROC_VERSION_2) {
pHttpCompletion = ecb;
ecb = UnsafeNativeMethods.GetEcb(pHttpCompletion);
}
ISAPIWorkerRequest wr = null;
try {
bool useOOP = (iWRType == WORKER_REQUEST_TYPE_OOP);
wr = ISAPIWorkerRequest.CreateWorkerRequest(ecb, useOOP);
wr.Initialize();
// check if app path matches (need to restart app domain?)
String wrPath = wr.GetAppPathTranslated();
String adPath = HttpRuntime.AppDomainAppPathInternal;
if (adPath == null ||
StringUtil.EqualsIgnoreCase(wrPath, adPath)) {
HttpRuntime.ProcessRequestNoDemand(wr);
return 0;
}
else {
// need to restart app domain
HttpRuntime.ShutdownAppDomain(ApplicationShutdownReason.PhysicalApplicationPathChanged,
SR.GetString(SR.Hosting_Phys_Path_Changed,
adPath,
wrPath));
return 1;
}
}
catch(Exception e) {
try {
WebBaseEvent.RaiseRuntimeError(e, this);
} catch {}
// Have we called HSE_REQ_DONE_WITH_SESSION? If so, don't re-throw.
if (wr != null && wr.Ecb == IntPtr.Zero) {
if (pHttpCompletion != IntPtr.Zero) {
UnsafeNativeMethods.SetDoneWithSessionCalled(pHttpCompletion);
}
// if this is a thread abort exception, cancel the abort
if (e is ThreadAbortException) {
Thread.ResetAbort();
}
// IMPORTANT: if this thread is being aborted because of an AppDomain.Unload,
// the CLR will still throw an AppDomainUnloadedException. The native caller
// must special case COR_E_APPDOMAINUNLOADED(0x80131014) and not
// call HSE_REQ_DONE_WITH_SESSION more than once.
return 0;
}
// re-throw if we have not called HSE_REQ_DONE_WITH_SESSION
throw;
}
}
///
/// [To be supplied.]
///
public void DoGCCollect() {
for (int c = 10; c > 0; c--) {
System.GC.Collect();
}
}
///
void IRegisteredObject.Stop(bool immediate) {
RemoveThisAppDomainFromUnmanagedTable();
HostingEnvironment.UnregisterObject(this);
}
internal static void RemoveThisAppDomainFromUnmanagedTable() {
if (Interlocked.Exchange(ref _isThisAppDomainRemovedFromUnmanagedTable, 1) != 0) {
return;
}
try {
String appId = HttpRuntime.AppDomainAppIdInternal;
if (appId != null ) {
Debug.Trace("ISAPIRuntime", "Calling UnsafeNativeMethods.AppDomainRestart appId=" + appId);
UnsafeNativeMethods.AppDomainRestart(appId);
}
HttpRuntime.AddAppDomainTraceMessage(SR.GetString(SR.App_Domain_Restart));
}
catch {
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CatalogPartCollection.cs
- SqlTransaction.cs
- ConfigurationManagerInternalFactory.cs
- DefaultValueTypeConverter.cs
- MDIWindowDialog.cs
- DbException.cs
- CommandValueSerializer.cs
- AccessViolationException.cs
- ContextStaticAttribute.cs
- HealthMonitoringSection.cs
- LinearGradientBrush.cs
- CodeAttributeDeclarationCollection.cs
- TextWriterEngine.cs
- CallbackValidatorAttribute.cs
- UiaCoreProviderApi.cs
- DeclarativeCatalogPart.cs
- HtmlFormWrapper.cs
- MultiAsyncResult.cs
- XamlRtfConverter.cs
- AddressHeaderCollectionElement.cs
- Splitter.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- CqlLexer.cs
- PowerStatus.cs
- RayHitTestParameters.cs
- BrowserCapabilitiesFactory.cs
- ControlDesigner.cs
- XPathScanner.cs
- XmlNotation.cs
- TargetControlTypeCache.cs
- Array.cs
- InkCollectionBehavior.cs
- ShutDownListener.cs
- ProxyElement.cs
- RenamedEventArgs.cs
- WebPartConnectVerb.cs
- ConfigXmlDocument.cs
- MouseOverProperty.cs
- AutomationProperty.cs
- EntityTypeEmitter.cs
- RequestCache.cs
- WindowsAuthenticationEventArgs.cs
- PageStatePersister.cs
- PasswordRecovery.cs
- If.cs
- MarkupCompilePass1.cs
- PermissionListSet.cs
- CompositeDataBoundControl.cs
- ClientEventManager.cs
- KeyInterop.cs
- WebPartCollection.cs
- CompilerResults.cs
- XmlAutoDetectWriter.cs
- WorkflowPersistenceService.cs
- HybridDictionary.cs
- HttpContext.cs
- BasicCellRelation.cs
- TemplateColumn.cs
- OleDbCommandBuilder.cs
- FormsAuthenticationModule.cs
- DragEventArgs.cs
- SqlServer2KCompatibilityCheck.cs
- TypedReference.cs
- XsltOutput.cs
- DeviceFiltersSection.cs
- EdmComplexPropertyAttribute.cs
- validationstate.cs
- ExtendedTransformFactory.cs
- ImageSource.cs
- WinFormsSpinner.cs
- ObjectDataProvider.cs
- RadioButton.cs
- AttributeAction.cs
- counter.cs
- Internal.cs
- BinaryFormatter.cs
- ComPlusDiagnosticTraceSchemas.cs
- ActivityBindForm.Designer.cs
- IRCollection.cs
- Int64AnimationUsingKeyFrames.cs
- FtpCachePolicyElement.cs
- CompiledRegexRunnerFactory.cs
- GradientStop.cs
- Point3DConverter.cs
- TraceContextRecord.cs
- AutomationPattern.cs
- TraceSection.cs
- FocusManager.cs
- RoleService.cs
- FacetChecker.cs
- GridItem.cs
- HttpSessionStateWrapper.cs
- MetadataItem_Static.cs
- x509utils.cs
- QueueProcessor.cs
- DataControlReference.cs
- TemplateBindingExpressionConverter.cs
- Utility.cs
- FormatSettings.cs
- CodeCommentStatement.cs