本文整理汇总了C#中System.Web.VirtualPath.ValidateState方法的典型用法代码示例。如果您正苦于以下问题:C# VirtualPath.ValidateState方法的具体用法?C# VirtualPath.ValidateState怎么用?C# VirtualPath.ValidateState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.VirtualPath
的用法示例。
在下文中一共展示了VirtualPath.ValidateState方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: Create
//.........这里部分代码省略.........
// Dev10 767308: optimize for normal paths, and scan once for
// i) invalid chars
// ii) slashes
// iii) '.'
bool slashes = false;
bool dot = false;
int len = virtualPath.Length;
unsafe {
fixed (char * p = virtualPath) {
for (int i = 0; i < len; i++) {
switch (p[i]) {
// need to fix slashes ?
case '/':
if (i > 0 && p[i-1] == '/')
slashes = true;
break;
case '\\':
slashes = true;
break;
// contains "." or ".."
case '.':
dot = true;
break;
// invalid chars
case '\0':
throw new HttpException(SR.GetString(SR.Invalid_vpath, virtualPath));
default:
break;
}
}
}
}
if (slashes) {
// If we're supposed to fail on malformed path, then throw
if ((options & VirtualPathOptions.FailIfMalformed) != 0) {
throw new HttpException(SR.GetString(SR.Invalid_vpath, virtualPath));
}
// Flip ----lashes, and remove duplicate slashes
virtualPath = UrlPath.FixVirtualPathSlashes(virtualPath);
}
// Make sure it ends with a trailing slash if requested
if ((options & VirtualPathOptions.EnsureTrailingSlash) != 0)
virtualPath = UrlPath.AppendSlashToPathIfNeeded(virtualPath);
VirtualPath virtualPathObject = new VirtualPath();
if (UrlPath.IsAppRelativePath(virtualPath)) {
if (dot)
virtualPath = UrlPath.ReduceVirtualPath(virtualPath);
if (virtualPath[0] == UrlPath.appRelativeCharacter) {
if ((options & VirtualPathOptions.AllowAppRelativePath) == 0) {
throw new ArgumentException(SR.GetString(SR.VirtualPath_AllowAppRelativePath, virtualPath));
}
virtualPathObject._appRelativeVirtualPath = virtualPath;
}
else {
// It's possible for the path to become absolute after calling Reduce,
// even though it started with "~/". e.g. if the app is "/app" and the path is
// "~/../hello.aspx", it becomes "/hello.aspx", which is absolute
if ((options & VirtualPathOptions.AllowAbsolutePath) == 0) {
throw new ArgumentException(SR.GetString(SR.VirtualPath_AllowAbsolutePath, virtualPath));
}
virtualPathObject._virtualPath = virtualPath;
}
}
else {
if (virtualPath[0] != '/') {
if ((options & VirtualPathOptions.AllowRelativePath) == 0) {
throw new ArgumentException(SR.GetString(SR.VirtualPath_AllowRelativePath, virtualPath));
}
// Don't Reduce relative paths, since the Reduce method is broken (e.g. "../foo.aspx" --> "/foo.aspx!")
//
virtualPathObject._virtualPath = virtualPath;
}
else {
if ((options & VirtualPathOptions.AllowAbsolutePath) == 0) {
throw new ArgumentException(SR.GetString(SR.VirtualPath_AllowAbsolutePath, virtualPath));
}
if (dot)
virtualPath = UrlPath.ReduceVirtualPath(virtualPath);
virtualPathObject._virtualPath = virtualPath;
}
}
#if DBG
virtualPathObject.ValidateState();
#endif
return virtualPathObject;
}
示例3: SimpleCombine
private VirtualPath SimpleCombine(string filename, bool addTrailingSlash) {
// The left part should always be a directory
Debug.Assert(HasTrailingSlash);
// The right part should not start or end with a slash
Debug.Assert(filename[0] != '/' && !UrlPath.HasTrailingSlash(filename));
// Use either _appRelativeVirtualPath or _virtualPath
string virtualPath = VirtualPathStringWhicheverAvailable + filename;
if (addTrailingSlash)
virtualPath += "/";
// Set the appropriate virtual path in the new object
VirtualPath combinedVirtualPath = new VirtualPath(virtualPath);
// Copy some flags over to avoid having to recalculate them
combinedVirtualPath.CopyFlagsFrom(this, isWithinAppRootComputed | isWithinAppRoot | appRelativeAttempted);
#if DBG
combinedVirtualPath.ValidateState();
#endif
return combinedVirtualPath;
}