本文整理汇总了C#中Url.AppendSegment方法的典型用法代码示例。如果您正苦于以下问题:C# Url.AppendSegment方法的具体用法?C# Url.AppendSegment怎么用?C# Url.AppendSegment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Url
的用法示例。
在下文中一共展示了Url.AppendSegment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Global_AuthenticateRequest
/// <summary>
/// Code to emulate IIS handling of folders / default documents.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>
/// Verify if this code is really needed when running under IIS7 - it could most likely be disabled then...
/// </remarks>
private void Global_AuthenticateRequest(object sender, EventArgs e)
{
// Emulate IIS directory redirection and default document handling.
string path = Request.Url.AbsolutePath;
// If we're referring to a directory but no document, try to find an existing default document.
if (path.EndsWith("/"))
{
// Get an array of possible choices for default documents.
string[] defaultDocuments = GetDefaultDocuments(Request.Url);
if (defaultDocuments != null)
{
foreach (string defaultDocument in defaultDocuments)
{
Url defaultUrl = new Url(Request.Url);
defaultUrl = defaultUrl.AppendSegment(defaultDocument);
// If this path actually exists...
if (HostingEnvironment.VirtualPathProvider.FileExists(defaultUrl.Path))
{
// ....rewrite the path to refer to this default document, and serve it up
HttpContext.Current.RewritePath(defaultUrl.Path + defaultUrl.Querystring);
break;
}
}
}
return;
}
// Request URL does not end with a slash, check if we have a corresponding directory
if (HostingEnvironment.VirtualPathProvider.DirectoryExists(path))
{
// TODO - check if this may be a problem - redirecting with host name?
// if we're referring to an existing directory, add a "/" and redirect
path += "/";
// NOTE! Since we are changing the nesting level of the request, we must do a redirect to ensure
// that the browser requesting the information is in sync with regards to the base URL.
Response.Redirect(path);
}
}