/// <summary> /// 重写Url /// </summary> /// <param name="sender">事件的源</param> /// <param name="e">包含事件数据的 EventArgs</param> private void ReUrl_BeginRequest(object sender, EventArgs e) { HttpContext context = ((HttpApplication)sender).Context; string requestPath = context.Request.Path.ToLower(); foreach (SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls) { if (Regex.IsMatch(requestPath, url.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase)) { string newUrl = Regex.Replace(requestPath, url.Pattern, url.QueryString, RegexOptions.Compiled | RegexOptions.IgnoreCase); context.RewritePath("/" + url.Page, string.Empty, newUrl); return; } } return; }