public void RewritePath_Exceptions(string input, string path, Type exception) { var source = new Uri(input); Assert.Throws(exception, () => { var output = source.Rewrite(path); }); }
// 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); }
// "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); } } }
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()); }
// 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); }