62,267
社区成员
发帖
与我相关
我的任务
分享
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Request.RawUrl.IndexOf(".xhtml") != -1)
{
string RawUrl = HttpContext.Current.Request.RawUrl.Replace(".xhtml", ".aspx");//将shtml转为aspx
Boolean isMatch = false;
#region 判断网页是否存在,如果存在不进行跳转
try
{
String tempURL = RawUrl;
if (tempURL.LastIndexOf("?") != -1)
{
tempURL = tempURL.Substring(0, tempURL.Length - (tempURL.Length - tempURL.LastIndexOf("?")));
}
if (System.IO.File.Exists(Server.MapPath(tempURL)))
{
isMatch = true;
}
}
catch { }
#endregion
#region 改写商品详细
if (isMatch == false)
{
Regex reg = new Regex(@"([^/]*)(.aspx)", RegexOptions.IgnoreCase);
Match m = reg.Match(RawUrl);
if (m.Success)
{
RawUrl = (Request.ApplicationPath + "/").Replace("//", "/") + "ProductView.aspx?MaterialCode=" + m.Groups[1].Value;
isMatch = true;
}
}
#endregion
Context.RewritePath(RawUrl);
}
}