Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / ndp / fx / src / xsp / System / Web / Hosting / SimpleWorkerRequest.cs / 2 / SimpleWorkerRequest.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Hosting {
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Web.Configuration;
using System.Web.Util;
//
// Simple Worker Request provides a concrete implementation
// of HttpWorkerRequest that writes the respone to the user
// supplied writer.
//
///
/// [To be supplied.]
///
[ComVisible(false)]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class SimpleWorkerRequest : HttpWorkerRequest {
private bool _hasRuntimeInfo;
private String _appVirtPath; // "/foo"
private String _appPhysPath; // "c:\foo\"
private String _page;
private String _pathInfo;
private String _queryString;
private TextWriter _output;
private String _installDir;
private void ExtractPagePathInfo() {
int i = _page.IndexOf('/');
if (i >= 0) {
_pathInfo = _page.Substring(i);
_page = _page.Substring(0, i);
}
}
private String GetPathInternal(bool includePathInfo) {
String s = _appVirtPath.Equals("/") ? ("/" + _page) : (_appVirtPath + "/" + _page);
if (includePathInfo && _pathInfo != null)
return s + _pathInfo;
else
return s;
}
//
// HttpWorkerRequest implementation
//
// "/foo/page.aspx/tail"
///
/// [To be supplied.]
///
public override String GetUriPath() {
return GetPathInternal(true);
}
// "param=bar"
///
/// [To be supplied.]
///
public override String GetQueryString() {
return _queryString;
}
// "/foo/page.aspx/tail?param=bar"
///
/// [To be supplied.]
///
public override String GetRawUrl() {
String qs = GetQueryString();
if (!String.IsNullOrEmpty(qs))
return GetPathInternal(true) + "?" + qs;
else
return GetPathInternal(true);
}
///
/// [To be supplied.]
///
public override String GetHttpVerbName() {
return "GET";
}
///
/// [To be supplied.]
///
public override String GetHttpVersion() {
return "HTTP/1.0";
}
///
/// [To be supplied.]
///
public override String GetRemoteAddress() {
return "127.0.0.1";
}
///
/// [To be supplied.]
///
public override int GetRemotePort() {
return 0;
}
///
/// [To be supplied.]
///
public override String GetLocalAddress() {
return "127.0.0.1";
}
///
/// [To be supplied.]
///
public override int GetLocalPort() {
return 80;
}
///
/// [To be supplied.]
///
public override IntPtr GetUserToken() {
return IntPtr.Zero;
}
///
/// [To be supplied.]
///
public override String GetFilePath() {
return GetPathInternal(false);
}
///
/// [To be supplied.]
///
public override String GetFilePathTranslated() {
String path = _appPhysPath + _page.Replace('/', '\\');
InternalSecurityPermissions.PathDiscovery(path).Demand();
return path;
}
///
/// [To be supplied.]
///
public override String GetPathInfo() {
return (_pathInfo != null) ? _pathInfo : String.Empty;
}
///
/// [To be supplied.]
///
public override String GetAppPath() {
return _appVirtPath;
}
///
/// [To be supplied.]
///
public override String GetAppPathTranslated() {
InternalSecurityPermissions.PathDiscovery(_appPhysPath).Demand();
return _appPhysPath;
}
///
/// [To be supplied.]
///
public override String GetServerVariable(String name) {
return String.Empty;
}
///
/// [To be supplied.]
///
public override String MapPath(String path) {
if (!_hasRuntimeInfo)
return null;
String mappedPath = null;
String appPath = _appPhysPath.Substring(0, _appPhysPath.Length-1); // without trailing "\"
if (String.IsNullOrEmpty(path) || path.Equals("/")) {
mappedPath = appPath;
}
if (StringUtil.StringStartsWith(path, _appVirtPath)) {
mappedPath = appPath + path.Substring(_appVirtPath.Length).Replace('/', '\\');
}
InternalSecurityPermissions.PathDiscovery(mappedPath).Demand();
return mappedPath;
}
///
/// [To be supplied.]
///
public override string MachineConfigPath {
get {
if (_hasRuntimeInfo) {
string path = HttpConfigurationSystem.MachineConfigurationFilePath;
InternalSecurityPermissions.PathDiscovery(path).Demand();
return path;
}
else
return null;
}
}
///
/// [To be supplied.]
///
public override string RootWebConfigPath {
get {
if (_hasRuntimeInfo) {
string path = HttpConfigurationSystem.RootWebConfigurationFilePath;
InternalSecurityPermissions.PathDiscovery(path).Demand();
return path;
}
else
return null;
}
}
///
/// [To be supplied.]
///
public override String MachineInstallDirectory {
get {
if (_hasRuntimeInfo) {
InternalSecurityPermissions.PathDiscovery(_installDir).Demand();
return _installDir;
}
return null;
}
}
///
/// [To be supplied.]
///
public override void SendStatus(int statusCode, String statusDescription) {
}
///
/// [To be supplied.]
///
public override void SendKnownResponseHeader(int index, String value) {
}
///
/// [To be supplied.]
///
public override void SendUnknownResponseHeader(String name, String value) {
}
///
/// [To be supplied.]
///
public override void SendResponseFromMemory(byte[] data, int length) {
_output.Write(System.Text.Encoding.Default.GetChars(data, 0, length));
}
///
/// [To be supplied.]
///
public override void SendResponseFromFile(String filename, long offset, long length) {
}
///
/// [To be supplied.]
///
public override void SendResponseFromFile(IntPtr handle, long offset, long length) {
}
///
/// [To be supplied.]
///
public override void FlushResponse(bool finalFlush) {
}
///
/// [To be supplied.]
///
public override void EndOfRequest() {
}
//
// Internal support
//
internal override void UpdateResponseCounters(bool finalFlush, int bytesOut) {
if (finalFlush) {
PerfCounters.DecrementGlobalCounter(GlobalPerfCounter.REQUESTS_CURRENT);
PerfCounters.DecrementCounter(AppPerfCounter.REQUESTS_EXECUTING);
}
if (bytesOut > 0) {
PerfCounters.IncrementCounterEx(AppPerfCounter.REQUEST_BYTES_OUT, bytesOut);
}
}
internal override void UpdateRequestCounters(int bytesIn) {
if (bytesIn > 0) {
PerfCounters.IncrementCounterEx(AppPerfCounter.REQUEST_BYTES_IN, bytesIn);
}
}
//
// Ctors
//
private SimpleWorkerRequest() {
PerfCounters.IncrementGlobalCounter(GlobalPerfCounter.REQUESTS_CURRENT);
PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_TOTAL);
}
/*
* Ctor that gets application data from HttpRuntime, assuming
* HttpRuntime has been set up (app domain specially created, etc.)
*/
///
/// [To be supplied.]
///
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
public SimpleWorkerRequest(String page, String query, TextWriter output): this() {
_queryString = query;
_output = output;
_page = page;
ExtractPagePathInfo();
_appPhysPath = Thread.GetDomain().GetData(".appPath").ToString();
_appVirtPath = Thread.GetDomain().GetData(".appVPath").ToString();
_installDir = HttpRuntime.AspInstallDirectoryInternal;
_hasRuntimeInfo = true;
}
/*
* Ctor that gets application data as arguments,assuming HttpRuntime
* has not been set up.
*
* This allows for limited functionality to execute handlers.
*/
///
/// [To be supplied.]
///
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
public SimpleWorkerRequest(String appVirtualDir, String appPhysicalDir, String page, String query, TextWriter output): this() {
if (Thread.GetDomain().GetData(".appPath") != null) {
throw new HttpException(SR.GetString(SR.Wrong_SimpleWorkerRequest));
}
_appVirtPath = appVirtualDir;
_appPhysPath = appPhysicalDir;
_queryString = query;
_output = output;
_page = page;
ExtractPagePathInfo();
if (!StringUtil.StringEndsWith(_appPhysPath, '\\'))
_appPhysPath += "\\";
_hasRuntimeInfo = false;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Hosting {
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Web.Configuration;
using System.Web.Util;
//
// Simple Worker Request provides a concrete implementation
// of HttpWorkerRequest that writes the respone to the user
// supplied writer.
//
///
/// [To be supplied.]
///
[ComVisible(false)]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class SimpleWorkerRequest : HttpWorkerRequest {
private bool _hasRuntimeInfo;
private String _appVirtPath; // "/foo"
private String _appPhysPath; // "c:\foo\"
private String _page;
private String _pathInfo;
private String _queryString;
private TextWriter _output;
private String _installDir;
private void ExtractPagePathInfo() {
int i = _page.IndexOf('/');
if (i >= 0) {
_pathInfo = _page.Substring(i);
_page = _page.Substring(0, i);
}
}
private String GetPathInternal(bool includePathInfo) {
String s = _appVirtPath.Equals("/") ? ("/" + _page) : (_appVirtPath + "/" + _page);
if (includePathInfo && _pathInfo != null)
return s + _pathInfo;
else
return s;
}
//
// HttpWorkerRequest implementation
//
// "/foo/page.aspx/tail"
///
/// [To be supplied.]
///
public override String GetUriPath() {
return GetPathInternal(true);
}
// "param=bar"
///
/// [To be supplied.]
///
public override String GetQueryString() {
return _queryString;
}
// "/foo/page.aspx/tail?param=bar"
///
/// [To be supplied.]
///
public override String GetRawUrl() {
String qs = GetQueryString();
if (!String.IsNullOrEmpty(qs))
return GetPathInternal(true) + "?" + qs;
else
return GetPathInternal(true);
}
///
/// [To be supplied.]
///
public override String GetHttpVerbName() {
return "GET";
}
///
/// [To be supplied.]
///
public override String GetHttpVersion() {
return "HTTP/1.0";
}
///
/// [To be supplied.]
///
public override String GetRemoteAddress() {
return "127.0.0.1";
}
///
/// [To be supplied.]
///
public override int GetRemotePort() {
return 0;
}
///
/// [To be supplied.]
///
public override String GetLocalAddress() {
return "127.0.0.1";
}
///
/// [To be supplied.]
///
public override int GetLocalPort() {
return 80;
}
///
/// [To be supplied.]
///
public override IntPtr GetUserToken() {
return IntPtr.Zero;
}
///
/// [To be supplied.]
///
public override String GetFilePath() {
return GetPathInternal(false);
}
///
/// [To be supplied.]
///
public override String GetFilePathTranslated() {
String path = _appPhysPath + _page.Replace('/', '\\');
InternalSecurityPermissions.PathDiscovery(path).Demand();
return path;
}
///
/// [To be supplied.]
///
public override String GetPathInfo() {
return (_pathInfo != null) ? _pathInfo : String.Empty;
}
///
/// [To be supplied.]
///
public override String GetAppPath() {
return _appVirtPath;
}
///
/// [To be supplied.]
///
public override String GetAppPathTranslated() {
InternalSecurityPermissions.PathDiscovery(_appPhysPath).Demand();
return _appPhysPath;
}
///
/// [To be supplied.]
///
public override String GetServerVariable(String name) {
return String.Empty;
}
///
/// [To be supplied.]
///
public override String MapPath(String path) {
if (!_hasRuntimeInfo)
return null;
String mappedPath = null;
String appPath = _appPhysPath.Substring(0, _appPhysPath.Length-1); // without trailing "\"
if (String.IsNullOrEmpty(path) || path.Equals("/")) {
mappedPath = appPath;
}
if (StringUtil.StringStartsWith(path, _appVirtPath)) {
mappedPath = appPath + path.Substring(_appVirtPath.Length).Replace('/', '\\');
}
InternalSecurityPermissions.PathDiscovery(mappedPath).Demand();
return mappedPath;
}
///
/// [To be supplied.]
///
public override string MachineConfigPath {
get {
if (_hasRuntimeInfo) {
string path = HttpConfigurationSystem.MachineConfigurationFilePath;
InternalSecurityPermissions.PathDiscovery(path).Demand();
return path;
}
else
return null;
}
}
///
/// [To be supplied.]
///
public override string RootWebConfigPath {
get {
if (_hasRuntimeInfo) {
string path = HttpConfigurationSystem.RootWebConfigurationFilePath;
InternalSecurityPermissions.PathDiscovery(path).Demand();
return path;
}
else
return null;
}
}
///
/// [To be supplied.]
///
public override String MachineInstallDirectory {
get {
if (_hasRuntimeInfo) {
InternalSecurityPermissions.PathDiscovery(_installDir).Demand();
return _installDir;
}
return null;
}
}
///
/// [To be supplied.]
///
public override void SendStatus(int statusCode, String statusDescription) {
}
///
/// [To be supplied.]
///
public override void SendKnownResponseHeader(int index, String value) {
}
///
/// [To be supplied.]
///
public override void SendUnknownResponseHeader(String name, String value) {
}
///
/// [To be supplied.]
///
public override void SendResponseFromMemory(byte[] data, int length) {
_output.Write(System.Text.Encoding.Default.GetChars(data, 0, length));
}
///
/// [To be supplied.]
///
public override void SendResponseFromFile(String filename, long offset, long length) {
}
///
/// [To be supplied.]
///
public override void SendResponseFromFile(IntPtr handle, long offset, long length) {
}
///
/// [To be supplied.]
///
public override void FlushResponse(bool finalFlush) {
}
///
/// [To be supplied.]
///
public override void EndOfRequest() {
}
//
// Internal support
//
internal override void UpdateResponseCounters(bool finalFlush, int bytesOut) {
if (finalFlush) {
PerfCounters.DecrementGlobalCounter(GlobalPerfCounter.REQUESTS_CURRENT);
PerfCounters.DecrementCounter(AppPerfCounter.REQUESTS_EXECUTING);
}
if (bytesOut > 0) {
PerfCounters.IncrementCounterEx(AppPerfCounter.REQUEST_BYTES_OUT, bytesOut);
}
}
internal override void UpdateRequestCounters(int bytesIn) {
if (bytesIn > 0) {
PerfCounters.IncrementCounterEx(AppPerfCounter.REQUEST_BYTES_IN, bytesIn);
}
}
//
// Ctors
//
private SimpleWorkerRequest() {
PerfCounters.IncrementGlobalCounter(GlobalPerfCounter.REQUESTS_CURRENT);
PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_TOTAL);
}
/*
* Ctor that gets application data from HttpRuntime, assuming
* HttpRuntime has been set up (app domain specially created, etc.)
*/
///
/// [To be supplied.]
///
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
public SimpleWorkerRequest(String page, String query, TextWriter output): this() {
_queryString = query;
_output = output;
_page = page;
ExtractPagePathInfo();
_appPhysPath = Thread.GetDomain().GetData(".appPath").ToString();
_appVirtPath = Thread.GetDomain().GetData(".appVPath").ToString();
_installDir = HttpRuntime.AspInstallDirectoryInternal;
_hasRuntimeInfo = true;
}
/*
* Ctor that gets application data as arguments,assuming HttpRuntime
* has not been set up.
*
* This allows for limited functionality to execute handlers.
*/
///
/// [To be supplied.]
///
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
public SimpleWorkerRequest(String appVirtualDir, String appPhysicalDir, String page, String query, TextWriter output): this() {
if (Thread.GetDomain().GetData(".appPath") != null) {
throw new HttpException(SR.GetString(SR.Wrong_SimpleWorkerRequest));
}
_appVirtPath = appVirtualDir;
_appPhysPath = appPhysicalDir;
_queryString = query;
_output = output;
_page = page;
ExtractPagePathInfo();
if (!StringUtil.StringEndsWith(_appPhysPath, '\\'))
_appPhysPath += "\\";
_hasRuntimeInfo = false;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- LogFlushAsyncResult.cs
- Bidi.cs
- AssemblyBuilderData.cs
- ParenthesizePropertyNameAttribute.cs
- ByteAnimation.cs
- Exceptions.cs
- Base64Decoder.cs
- _LocalDataStoreMgr.cs
- WebPartVerb.cs
- MenuBase.cs
- ListBoxItemAutomationPeer.cs
- WebPartConnectionsConnectVerb.cs
- RequestCachePolicy.cs
- ArcSegment.cs
- LockRenewalTask.cs
- ResourceWriter.cs
- EndpointConfigContainer.cs
- WSTrust.cs
- ObjectDataSource.cs
- InlineCollection.cs
- FixedSOMTable.cs
- HealthMonitoringSectionHelper.cs
- followingquery.cs
- NotImplementedException.cs
- DeadCharTextComposition.cs
- PackWebRequestFactory.cs
- ClonableStack.cs
- HostedElements.cs
- DiscoveryClientElement.cs
- EntityTypeEmitter.cs
- StringArrayConverter.cs
- ForceCopyBuildProvider.cs
- TagPrefixInfo.cs
- propertyentry.cs
- Vector3DIndependentAnimationStorage.cs
- Predicate.cs
- TextPointer.cs
- VirtualizingPanel.cs
- FileSystemEventArgs.cs
- datacache.cs
- WbemProvider.cs
- SettingsAttributes.cs
- ResourceDisplayNameAttribute.cs
- XmlAnyElementAttribute.cs
- PersonalizablePropertyEntry.cs
- NamespaceCollection.cs
- ImageCollectionCodeDomSerializer.cs
- SettingsPropertyCollection.cs
- TreeNodeCollectionEditor.cs
- MailDefinition.cs
- OutputCacheSection.cs
- Helpers.cs
- DataGridViewRowCancelEventArgs.cs
- NetCodeGroup.cs
- GiveFeedbackEvent.cs
- TextDecorationCollection.cs
- TextAutomationPeer.cs
- CacheMode.cs
- ComponentTray.cs
- CompositeKey.cs
- _KerberosClient.cs
- ServicePointManagerElement.cs
- AttributeTable.cs
- Size3DValueSerializer.cs
- PropertyMetadata.cs
- CodeIdentifier.cs
- HyperLink.cs
- XamlPathDataSerializer.cs
- CharacterBufferReference.cs
- CodeEventReferenceExpression.cs
- LoginView.cs
- ScrollContentPresenter.cs
- ReadOnlyPermissionSet.cs
- ListBox.cs
- TreeNodeSelectionProcessor.cs
- DataRowChangeEvent.cs
- ComponentRenameEvent.cs
- AnnotationComponentManager.cs
- EventItfInfo.cs
- BamlTreeUpdater.cs
- Rotation3D.cs
- DataGridViewHitTestInfo.cs
- AlphabetConverter.cs
- EntityClientCacheEntry.cs
- GPPOINTF.cs
- CodeTypeMemberCollection.cs
- GiveFeedbackEvent.cs
- RowsCopiedEventArgs.cs
- ZoneMembershipCondition.cs
- ParallelTimeline.cs
- RegexBoyerMoore.cs
- XmlQualifiedNameTest.cs
- RegexStringValidator.cs
- DataBoundControlAdapter.cs
- linebase.cs
- FtpWebRequest.cs
- PropertyMap.cs
- TextTreeTextNode.cs
- PinnedBufferMemoryStream.cs
- RangeBase.cs