本文整理汇总了C#中System.Uri.Rewrite方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.Rewrite方法的具体用法?C# Uri.Rewrite怎么用?C# Uri.Rewrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Uri
的用法示例。
在下文中一共展示了Uri.Rewrite方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RewritePath_Exceptions
public void RewritePath_Exceptions(string input, string path, Type exception)
{
var source = new Uri(input);
Assert.Throws(exception, () =>
{
var output = source.Rewrite(path);
});
}
示例2: UriFromUmbraco
// maps an internal umbraco uri to a public uri
// ie with virtual directory, .aspx if required...
public static Uri UriFromUmbraco(Uri uri)
{
var path = uri.GetSafeAbsolutePath();
if (path != "/")
{
if (!GlobalSettings.UseDirectoryUrls)
path += ".aspx";
else if (UmbracoSettings.AddTrailingSlash)
path += "/";
}
path = ToAbsolute(path);
return uri.Rewrite(path);
}
示例3: LegacyCleanUmbPageFromQueryString
// "Clean umbPage from querystring, caused by .NET 2.0 default Auth Controls"
// but really, at the moment I have no idea what this does, and why...
// SD: I also have no idea what this does, I've googled umbPage and really nothing shows up
internal static void LegacyCleanUmbPageFromQueryString(ref Uri uri)
{
string receivedQuery = uri.Query;
string path = uri.AbsolutePath;
string query = null;
if (receivedQuery.Length > 0)
{
// Clean umbPage from querystring, caused by .NET 2.0 default Auth Controls
if (receivedQuery.IndexOf("umbPage") > 0)
{
int ampPos = receivedQuery.IndexOf('&');
// query contains no ampersand?
if (ampPos < 0)
{
// no ampersand means no original query string
query = String.Empty;
// ampersand would occur past then end the of received query
ampPos = receivedQuery.Length;
}
else
{
// original query string past ampersand
query = receivedQuery.Substring(ampPos + 1,
receivedQuery.Length - ampPos - 1);
}
// get umbPage out of query string (9 = "&umbPage".Length() + 1)
path = receivedQuery.Substring(9, ampPos - 9); //this will fail if there are < 9 characters before the &umbPage query string
// --added when refactoring--
uri = uri.Rewrite(path, query);
}
}
}
示例4: RewritePathAndQuery
public void RewritePathAndQuery(string input, string path, string query, string expected)
{
var source = new Uri(input);
var output = source.Rewrite(path, query);
Assert.AreEqual(expected, output.ToString());
}
示例5: UriToUmbraco
// maps a public uri to an internal umbraco uri
// ie no virtual directory, no .aspx, lowercase...
public static Uri UriToUmbraco(Uri uri)
{
// note: no need to decode uri here because we're returning a uri
// so it will be re-encoded anyway
var path = uri.GetSafeAbsolutePath();
path = path.ToLower();
path = ToAppRelative(path); // strip vdir if any
//we need to check if the path is /default.aspx because this will occur when using a
//web server pre IIS 7 when requesting the root document
//if this is the case we need to change it to '/'
if (path.StartsWith("/default.aspx", StringComparison.InvariantCultureIgnoreCase))
{
string rempath = path.Substring("/default.aspx".Length, path.Length - "/default.aspx".Length);
path = rempath.StartsWith("/") ? rempath : "/" + rempath;
}
if (path != "/")
{
path = path.TrimEnd('/');
}
//if any part of the path contains .aspx, replace it with nothing.
//sometimes .aspx is not at the end since we might have /home/sub1.aspx/customtemplate
path = path.Replace(".aspx", "");
return uri.Rewrite(path);
}