<%@ Application Language="C
#" %>
<script RunAt="server">
void Application_BeginRequest(object sender, Event
args e)
{
string oldUrl =
System.Web.HttpContext.
current.Request.RawUrl; //获取初始url
//~/123.aspx → ~/Index.aspx?id=123
Regex reg = new Regex(@"^\/\d+\.ht
ML");
if (reg.IsMatch(oldUrl))
{
string id = reg.Match(oldUrl).ToString().S
ubstring(1, reg.Match(oldUrl).ToString().LastIndexOf(".") - 1);
Context.Rewr
ITePath("~/Index.aspx?id=" + id);
}
//~/123 → ~/Index.aspx?id=123
Regex reg1 = new Regex(@"^\/\d+$");
if (reg1.IsMatch(oldUrl))
{
string id = reg1.Match(oldUrl).ToString().Substring(1);
Context.RewritePath("~/Index.aspx?id=" + id);
}
//~/index/123 → ~/Index.aspx?id=123
Regex reg3 = new Regex(@"^\/index\/\d+$");
if (reg3.IsMatch(oldUrl))
{
string id = reg3.Match(oldUrl).ToString().Substring(7);
Context.RewritePath("~/Index.aspx?id=" + id);
}
}
</script>