本文整理汇总了C#中System.Web.VirtualPath.FailIfRelativePath方法的典型用法代码示例。如果您正苦于以下问题:C# VirtualPath.FailIfRelativePath方法的具体用法?C# VirtualPath.FailIfRelativePath怎么用?C# VirtualPath.FailIfRelativePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.VirtualPath
的用法示例。
在下文中一共展示了VirtualPath.FailIfRelativePath方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVirtualPathData
//
// Get CachedPathData for a virtual path.
// The path may be supplied by user code, so check that it is valid.
//
static internal CachedPathData GetVirtualPathData(VirtualPath virtualPath, bool permitPathsOutsideApp) {
if (!HostingEnvironment.IsHosted) {
return GetRootWebPathData();
}
// Make sure it's not relative
if (virtualPath != null) {
virtualPath.FailIfRelativePath();
}
// Check if the path is within the application.
if (virtualPath == null || !virtualPath.IsWithinAppRoot) {
if (permitPathsOutsideApp) {
return GetApplicationPathData();
}
else {
throw new ArgumentException(SR.GetString(SR.Cross_app_not_allowed,
(virtualPath != null) ? virtualPath.VirtualPathString : "null"));
}
}
// Construct a configPath based on the unvalidated virtualPath.
string configPath = WebConfigurationHost.GetConfigPathFromSiteIDAndVPath(HostingEnvironment.SiteID, virtualPath);
// Pass the virtualPath to GetConfigPathData to validate in the case where the
// CachedPathData for the unsafeConfigPath is not found.
return GetConfigPathData(configPath);
}
示例2: Combine
internal static VirtualPath Combine(VirtualPath v1, VirtualPath v2) {
// If the first is null, use the app root instead
if (v1 == null) {
v1 = HttpRuntime.AppDomainAppVirtualPathObject;
}
// If the first is still null, return the second, unless it's relative
if (v1 == null) {
v2.FailIfRelativePath();
return v2;
}
return v1.Combine(v2);
}
示例3: MakeRelative
public VirtualPath MakeRelative(VirtualPath toVirtualPath) {
VirtualPath resultVirtualPath = new VirtualPath();
// Neither path can be relative
FailIfRelativePath();
toVirtualPath.FailIfRelativePath();
// Set it directly since we know the slashes are already ok
resultVirtualPath._virtualPath = UrlPath.MakeRelative(this.VirtualPathString, toVirtualPath.VirtualPathString);
#if DBG
resultVirtualPath.ValidateState();
#endif
return resultVirtualPath;
}
示例4: MapPathActual
private string MapPathActual(VirtualPath virtualPath, bool permitNull)
{
string result = null;
Debug.Assert(virtualPath != null);
virtualPath.FailIfRelativePath();
VirtualPath reqpath = virtualPath;
if (String.CompareOrdinal(reqpath.VirtualPathString, _appVirtualPath.VirtualPathString) == 0) {
// for application path don't need to call app host
Debug.Trace("MapPath", reqpath +" is the app path");
result = _appPhysicalPath;
}
else {
using (new ProcessImpersonationContext()) {
// If there is a mapping for this virtual path in the call context, use it
result = GetVirtualPathToFileMapping(reqpath);
if (result == null) {
// call host's mappath
if (_configMapPath == null) {
Debug.Trace("MapPath", "Missing _configMapPath");
throw new InvalidOperationException(SR.GetString(SR.Cannot_map_path, reqpath));
}
Debug.Trace("MapPath", "call ConfigMapPath (" + reqpath + ")");
// see if the IConfigMapPath provider implements the interface
// with VirtualPath
try {
if (null != _configMapPath2) {
result = _configMapPath2.MapPath(GetSiteID(), reqpath);
}
else {
result = _configMapPath.MapPath(GetSiteID(), reqpath.VirtualPathString);
}
if (HttpRuntime.IsMapPathRelaxed)
result = HttpRuntime.GetRelaxedMapPathResult(result);
} catch {
if (HttpRuntime.IsMapPathRelaxed)
result = HttpRuntime.GetRelaxedMapPathResult(null);
else
throw;
}
}
}
}
if (String.IsNullOrEmpty(result)) {
Debug.Trace("MapPath", "null Result");
if (!permitNull) {
if (HttpRuntime.IsMapPathRelaxed)
result = HttpRuntime.GetRelaxedMapPathResult(null);
else
throw new InvalidOperationException(SR.GetString(SR.Cannot_map_path, reqpath));
}
}
else {
// ensure extra '\\' in the physical path if the virtual path had extra '/'
// and the other way -- no extra '\\' in physical if virtual didn't have it.
if (virtualPath.HasTrailingSlash) {
if (!UrlPath.PathEndsWithExtraSlash(result) && !UrlPath.PathIsDriveRoot(result))
result = result + "\\";
}
else {
if (UrlPath.PathEndsWithExtraSlash(result) && !UrlPath.PathIsDriveRoot(result))
result = result.Substring(0, result.Length - 1);
}
Debug.Trace("MapPath", " result=" + result);
}
return result;
}
示例5: MapPathActual
private string MapPathActual(VirtualPath virtualPath, bool permitNull)
{
string originalResult = null;
virtualPath.FailIfRelativePath();
VirtualPath path = virtualPath;
if (string.CompareOrdinal(path.VirtualPathString, this._appVirtualPath.VirtualPathString) == 0)
{
originalResult = this._appPhysicalPath;
}
else
{
using (new ProcessImpersonationContext())
{
originalResult = GetVirtualPathToFileMapping(path);
if (originalResult == null)
{
if (this._configMapPath == null)
{
throw new InvalidOperationException(System.Web.SR.GetString("Cannot_map_path", new object[] { path }));
}
try
{
if (this._configMapPath2 != null)
{
originalResult = this._configMapPath2.MapPath(this.GetSiteID(), path);
}
else
{
originalResult = this._configMapPath.MapPath(this.GetSiteID(), path.VirtualPathString);
}
if (HttpRuntime.IsMapPathRelaxed)
{
originalResult = HttpRuntime.GetRelaxedMapPathResult(originalResult);
}
}
catch
{
if (!HttpRuntime.IsMapPathRelaxed)
{
throw;
}
originalResult = HttpRuntime.GetRelaxedMapPathResult(null);
}
}
}
}
if (string.IsNullOrEmpty(originalResult))
{
if (permitNull)
{
return originalResult;
}
if (!HttpRuntime.IsMapPathRelaxed)
{
throw new InvalidOperationException(System.Web.SR.GetString("Cannot_map_path", new object[] { path }));
}
return HttpRuntime.GetRelaxedMapPathResult(null);
}
if (virtualPath.HasTrailingSlash)
{
if (!UrlPath.PathEndsWithExtraSlash(originalResult) && !UrlPath.PathIsDriveRoot(originalResult))
{
originalResult = originalResult + @"\";
}
return originalResult;
}
if (UrlPath.PathEndsWithExtraSlash(originalResult) && !UrlPath.PathIsDriveRoot(originalResult))
{
originalResult = originalResult.Substring(0, originalResult.Length - 1);
}
return originalResult;
}
示例6: GetVirtualPathData
internal static CachedPathData GetVirtualPathData(VirtualPath virtualPath, bool permitPathsOutsideApp)
{
if (!HostingEnvironment.IsHosted)
{
return GetRootWebPathData();
}
if (virtualPath != null)
{
virtualPath.FailIfRelativePath();
}
if ((virtualPath != null) && virtualPath.IsWithinAppRoot)
{
return GetConfigPathData(WebConfigurationHost.GetConfigPathFromSiteIDAndVPath(HostingEnvironment.SiteID, virtualPath));
}
if (!permitPathsOutsideApp)
{
throw new ArgumentException(System.Web.SR.GetString("Cross_app_not_allowed", new object[] { (virtualPath != null) ? virtualPath.VirtualPathString : "null" }));
}
return GetApplicationPathData();
}