Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / xsp / System / Web / Configuration / VirtualDirectoryMapping.cs / 1 / VirtualDirectoryMapping.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Configuration {
using System;
using System.Configuration;
using System.IO;
using System.Web.Util;
using System.Security.Permissions;
//
// Maps a virtual directory to a physical directory and its config file.
//
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class VirtualDirectoryMapping {
VirtualPath _virtualDirectory;
string _physicalDirectory;
string _configFileBaseName;
bool _isAppRoot;
const string DEFAULT_BASE_NAME = "web.config";
public VirtualDirectoryMapping(string physicalDirectory, bool isAppRoot)
: this(null, physicalDirectory, isAppRoot, DEFAULT_BASE_NAME) {
}
public VirtualDirectoryMapping(string physicalDirectory, bool isAppRoot, string configFileBaseName)
: this(null, physicalDirectory, isAppRoot, configFileBaseName) {
}
private VirtualDirectoryMapping(VirtualPath virtualDirectory, string physicalDirectory, bool isAppRoot, string configFileBaseName) {
_virtualDirectory = virtualDirectory;
_isAppRoot = isAppRoot;
PhysicalDirectory = physicalDirectory;
ConfigFileBaseName = configFileBaseName;
}
internal VirtualDirectoryMapping Clone() {
return new VirtualDirectoryMapping(_virtualDirectory, _physicalDirectory, _isAppRoot, _configFileBaseName);
}
//
// Get the virtual directory.
// Not settable because it is set when it is added to a collection.
//
public string VirtualDirectory {
get {
return (_virtualDirectory != null) ? _virtualDirectory.VirtualPathString : string.Empty;
}
}
internal VirtualPath VirtualDirectoryObject {
get {
return _virtualDirectory;
}
}
internal void SetVirtualDirectory(VirtualPath virtualDirectory) {
_virtualDirectory = virtualDirectory;
}
//
// The physical directory.
//
public string PhysicalDirectory {
get {
return _physicalDirectory;
}
set {
string physicalDirectory = value;
if (String.IsNullOrEmpty(physicalDirectory)) {
physicalDirectory = null;
}
else {
// remove trailing '\' if any
if (UrlPath.PathEndsWithExtraSlash(physicalDirectory)) {
physicalDirectory = physicalDirectory.Substring(0, physicalDirectory.Length - 1);
}
// Throw if the resulting physical path is not canonical, to prevent potential
// security issues (VSWhidbey 418125)
if (FileUtil.IsSuspiciousPhysicalPath(physicalDirectory)) {
throw ExceptionUtil.ParameterInvalid("PhysicalDirectory");
}
}
_physicalDirectory = physicalDirectory;
}
}
//
// Indicates whether the virtual directory is the location of an application.
//
public bool IsAppRoot {
get {
return _isAppRoot;
}
set {
_isAppRoot = value;
}
}
//
// The base name of the config file.
// If not specified, "web.config" is used.
//
public string ConfigFileBaseName {
get {
return _configFileBaseName;
}
set {
if (string.IsNullOrEmpty(value)) {
throw ExceptionUtil.PropertyInvalid("ConfigFileBaseName");
}
_configFileBaseName = value;
}
}
internal void Validate() {
if (_physicalDirectory != null) {
//
// Ensure that the caller has PathDiscovery to the resulting config file,
// and that the web.config file does not have ".." that could lead to a
// different directory.
//
string configFilename = Path.Combine(_physicalDirectory, _configFileBaseName);
string fullConfigFilename = Path.GetFullPath(configFilename);
if ( Path.GetDirectoryName(fullConfigFilename) != _physicalDirectory ||
Path.GetFileName(fullConfigFilename) != _configFileBaseName ||
FileUtil.IsSuspiciousPhysicalPath(configFilename)) {
throw ExceptionUtil.ParameterInvalid("configFileBaseName");
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Configuration {
using System;
using System.Configuration;
using System.IO;
using System.Web.Util;
using System.Security.Permissions;
//
// Maps a virtual directory to a physical directory and its config file.
//
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class VirtualDirectoryMapping {
VirtualPath _virtualDirectory;
string _physicalDirectory;
string _configFileBaseName;
bool _isAppRoot;
const string DEFAULT_BASE_NAME = "web.config";
public VirtualDirectoryMapping(string physicalDirectory, bool isAppRoot)
: this(null, physicalDirectory, isAppRoot, DEFAULT_BASE_NAME) {
}
public VirtualDirectoryMapping(string physicalDirectory, bool isAppRoot, string configFileBaseName)
: this(null, physicalDirectory, isAppRoot, configFileBaseName) {
}
private VirtualDirectoryMapping(VirtualPath virtualDirectory, string physicalDirectory, bool isAppRoot, string configFileBaseName) {
_virtualDirectory = virtualDirectory;
_isAppRoot = isAppRoot;
PhysicalDirectory = physicalDirectory;
ConfigFileBaseName = configFileBaseName;
}
internal VirtualDirectoryMapping Clone() {
return new VirtualDirectoryMapping(_virtualDirectory, _physicalDirectory, _isAppRoot, _configFileBaseName);
}
//
// Get the virtual directory.
// Not settable because it is set when it is added to a collection.
//
public string VirtualDirectory {
get {
return (_virtualDirectory != null) ? _virtualDirectory.VirtualPathString : string.Empty;
}
}
internal VirtualPath VirtualDirectoryObject {
get {
return _virtualDirectory;
}
}
internal void SetVirtualDirectory(VirtualPath virtualDirectory) {
_virtualDirectory = virtualDirectory;
}
//
// The physical directory.
//
public string PhysicalDirectory {
get {
return _physicalDirectory;
}
set {
string physicalDirectory = value;
if (String.IsNullOrEmpty(physicalDirectory)) {
physicalDirectory = null;
}
else {
// remove trailing '\' if any
if (UrlPath.PathEndsWithExtraSlash(physicalDirectory)) {
physicalDirectory = physicalDirectory.Substring(0, physicalDirectory.Length - 1);
}
// Throw if the resulting physical path is not canonical, to prevent potential
// security issues (VSWhidbey 418125)
if (FileUtil.IsSuspiciousPhysicalPath(physicalDirectory)) {
throw ExceptionUtil.ParameterInvalid("PhysicalDirectory");
}
}
_physicalDirectory = physicalDirectory;
}
}
//
// Indicates whether the virtual directory is the location of an application.
//
public bool IsAppRoot {
get {
return _isAppRoot;
}
set {
_isAppRoot = value;
}
}
//
// The base name of the config file.
// If not specified, "web.config" is used.
//
public string ConfigFileBaseName {
get {
return _configFileBaseName;
}
set {
if (string.IsNullOrEmpty(value)) {
throw ExceptionUtil.PropertyInvalid("ConfigFileBaseName");
}
_configFileBaseName = value;
}
}
internal void Validate() {
if (_physicalDirectory != null) {
//
// Ensure that the caller has PathDiscovery to the resulting config file,
// and that the web.config file does not have ".." that could lead to a
// different directory.
//
string configFilename = Path.Combine(_physicalDirectory, _configFileBaseName);
string fullConfigFilename = Path.GetFullPath(configFilename);
if ( Path.GetDirectoryName(fullConfigFilename) != _physicalDirectory ||
Path.GetFileName(fullConfigFilename) != _configFileBaseName ||
FileUtil.IsSuspiciousPhysicalPath(configFilename)) {
throw ExceptionUtil.ParameterInvalid("configFileBaseName");
}
}
}
}
}
// 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
- TemplateBindingExtensionConverter.cs
- FontWeights.cs
- Literal.cs
- RangeBaseAutomationPeer.cs
- EntitySetBase.cs
- PixelFormat.cs
- SortFieldComparer.cs
- RtType.cs
- ExceptionWrapper.cs
- WindowsListView.cs
- Pkcs9Attribute.cs
- InternalBufferManager.cs
- AcceptorSessionSymmetricTransportSecurityProtocol.cs
- SuspendDesigner.cs
- AutomationPropertyInfo.cs
- XhtmlTextWriter.cs
- Transform3D.cs
- TreeNodeEventArgs.cs
- WindowsImpersonationContext.cs
- SocketElement.cs
- PriorityBindingExpression.cs
- DrawItemEvent.cs
- DbProviderFactoriesConfigurationHandler.cs
- BitmapVisualManager.cs
- WorkflowInstance.cs
- ServerIdentity.cs
- SoapObjectReader.cs
- SecurityHeaderTokenResolver.cs
- SuppressMergeCheckAttribute.cs
- ScrollBarAutomationPeer.cs
- PathHelper.cs
- ValueTable.cs
- StreamWriter.cs
- UIElementPropertyUndoUnit.cs
- LoginViewDesigner.cs
- GradientStop.cs
- ServiceEndpointCollection.cs
- MatrixCamera.cs
- ColumnBinding.cs
- SqlClientFactory.cs
- ControlCommandSet.cs
- StrokeNodeOperations2.cs
- CalendarDay.cs
- UnsafeNativeMethods.cs
- ImageFormatConverter.cs
- ObjectCloneHelper.cs
- Drawing.cs
- IUnknownConstantAttribute.cs
- ExecutedRoutedEventArgs.cs
- SQLInt64Storage.cs
- SelectionList.cs
- ListChunk.cs
- HttpCookie.cs
- PackageDigitalSignature.cs
- GeneralTransformGroup.cs
- DoubleCollectionConverter.cs
- StorageComplexTypeMapping.cs
- Point3DCollection.cs
- WindowClosedEventArgs.cs
- ToolZone.cs
- VariableElement.cs
- EntityDataSourceDataSelection.cs
- HyperlinkAutomationPeer.cs
- LinkTarget.cs
- ConstructorExpr.cs
- DataServiceQueryProvider.cs
- EntityDataSourceMemberPath.cs
- DrawingCollection.cs
- SiteMap.cs
- DataContractSerializerOperationFormatter.cs
- AutoGeneratedFieldProperties.cs
- ScaleTransform.cs
- ObservableDictionary.cs
- Keywords.cs
- StylusEditingBehavior.cs
- Attribute.cs
- Decoder.cs
- VariantWrapper.cs
- TreeIterator.cs
- CharacterMetrics.cs
- DeviceContext2.cs
- FileDialogPermission.cs
- BuildProvider.cs
- WebReferencesBuildProvider.cs
- BamlRecordReader.cs
- ToolStripGripRenderEventArgs.cs
- TextTreeDeleteContentUndoUnit.cs
- RepeatBehaviorConverter.cs
- QilBinary.cs
- Site.cs
- LogConverter.cs
- LocalizableResourceBuilder.cs
- TextElement.cs
- listitem.cs
- DataListItemCollection.cs
- Brush.cs
- DataGridTableCollection.cs
- StreamAsIStream.cs
- MemberJoinTreeNode.cs
- XmlDocumentSerializer.cs