Global.Application asaxBeginRequest에서 URL을 접미사 없는 코드로 다시 쓰기

1361 단어
글로벌을 이용하다.Application asaxBeginRequest URL 다시 쓰기 접미어 없음
 
  


<br>void Application_BeginRequest(object sender, EventArgs e) <br>{ <br>string oldUrl = System.Web.HttpContext.Current.Request.RawUrl; // url <br> <br>//~/123.aspx → ~/Index.aspx?id=123 <br>Regex reg = new Regex(@"^\/\d+\.html"); <br>if (reg.IsMatch(oldUrl)) <br>{ <br>string id = reg.Match(oldUrl).ToString().Substring(1, reg.Match(oldUrl).ToString().LastIndexOf(".") - 1); <br>Context.RewritePath("~/Index.aspx?id=" + id); <br>} <br> <br>//~/123 → ~/Index.aspx?id=123 <br>Regex reg1 = new Regex(@"^\/\d+$"); <br>if (reg1.IsMatch(oldUrl)) <br>{ <br>string id = reg1.Match(oldUrl).ToString().Substring(1); <br>Context.RewritePath("~/Index.aspx?id=" + id); <br>} <br> <br>//~/index/123 → ~/Index.aspx?id=123 <br>Regex reg3 = new Regex(@"^\/index\/\d+$"); <br>if (reg3.IsMatch(oldUrl)) <br>{ <br>string id = reg3.Match(oldUrl).ToString().Substring(7); <br>Context.RewritePath("~/Index.aspx?id=" + id); <br>} <br>} <br> <br>

좋은 웹페이지 즐겨찾기