123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System;
- using System.Web;
- namespace URLRewriter
- {
-
-
-
-
-
- internal class RewriterUtils
- {
- #region RewriteUrl
-
-
-
-
-
- internal static void RewriteUrl(HttpContext context, string sendToUrl)
- {
- string x, y;
- RewriteUrl(context, sendToUrl, out x, out y);
- }
-
-
-
-
-
-
-
- internal static void RewriteUrl(HttpContext context, string sendToUrl, out string sendToUrlLessQString, out string filePath)
- {
-
- if (context.Request.QueryString.Count > 0)
- {
- if (sendToUrl.IndexOf('?') != -1)
- sendToUrl += "&" + context.Request.QueryString.ToString();
- else
- sendToUrl += "?" + context.Request.QueryString.ToString();
- }
-
- string queryString = String.Empty;
- sendToUrlLessQString = sendToUrl;
- if (sendToUrl.IndexOf('?') > 0)
- {
- sendToUrlLessQString = sendToUrl.Substring(0, sendToUrl.IndexOf('?'));
- queryString = sendToUrl.Substring(sendToUrl.IndexOf('?') + 1);
- }
-
- filePath = string.Empty;
- filePath = context.Server.MapPath(sendToUrlLessQString);
-
- context.RewritePath(sendToUrlLessQString, String.Empty, queryString);
-
-
-
- }
- #endregion
-
-
-
-
-
-
-
-
-
- internal static string ResolveUrl(string appPath, string url)
- {
- if (url.Length == 0 || url[0] != '~')
- return url;
- else
- {
- if (url.Length == 1)
- return appPath;
- if (url[1] == '/' || url[1] == '\\')
- {
-
- if (appPath.Length > 1)
- return appPath + "/" + url.Substring(2);
- else
- return "/" + url.Substring(2);
- }
- else
- {
-
- if (appPath.Length > 1)
- return appPath + "/" + url.Substring(1);
- else
- return appPath + url.Substring(1);
- }
- }
- }
- }
- }
|