62,025
社区成员
发帖
与我相关
我的任务
分享
pattern = string.Format(@"/(.[0-9a-zA-Z]*)/$");
if (Regex.IsMatch(requestPath, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled))
{
string file = requestPath.Substring(0, requestPath.Length - 1) + ".aspx"; ;
file = Server.MapPath("~" + file);
if (System.IO.File.Exists(file))
file = "/$1.aspx";
else
file = "/default.aspx?param=$1";
string newUrl = Regex.Replace(requestPath, pattern, file, RegexOptions.IgnoreCase | RegexOptions.Compiled);
Context.RewritePath(newUrl);
}
pattern = string.Format(@"/(.[0-9a-zA-Z]*)/$");
if (Regex.IsMatch(requestPath, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled))
{
string file = requestPath.Substring(0, requestPath.Length - 1) + ".aspx"; ;
file = Server.MapPath("~" + file);
if (System.IO.File.Exists(file))
file = "/$1.aspx";
else
file = "/default.aspx?param=$1";
// 这里的问题, /default.aspx?param=$1 代表的是根目录,需要把路径加到这里,用这则提取一下路径加进来就行 了
string newUrl = Regex.Replace(requestPath, pattern, file, RegexOptions.IgnoreCase | RegexOptions.Compiled);
Context.RewritePath(newUrl);
}