国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Global.asax的Application_BeginRequest實現url重寫無后綴的代碼

2020-01-17 23:47:16
字體:
來源:轉載
供稿:網友
利用Global.asax的Application_BeginRequest 實現url 重寫 無后綴
復制代碼 代碼如下:

<%@ Application Language="C#" %>

<script RunAt="server">
void Application_BeginRequest(object sender, EventArgs e)
{
string oldUrl = System.Web.HttpContext.Current.Request.RawUrl; //獲取初始url

//~/123.aspx → ~/Index.aspx?id=123
Regex reg = new Regex(@"^///d+/.html");
if (reg.IsMatch(oldUrl))
{
string id = reg.Match(oldUrl).ToString().Substring(1, reg.Match(oldUrl).ToString().LastIndexOf(".") - 1);
Context.RewritePath("~/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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 攀枝花市| 金乡县| 曲水县| 齐齐哈尔市| 泰兴市| 亳州市| 合水县| 肇州县| 双牌县| 湖州市| 洛阳市| 台山市| 宁德市| 廉江市| 泉州市| 前郭尔| 红河县| 纳雍县| 新郑市| 阿巴嘎旗| 西乡县| 高雄县| 大埔区| 鸡泽县| 平舆县| 宕昌县| 海林市| 思南县| 五原县| 桦川县| 铁力市| 库伦旗| 烟台市| 南昌县| 襄汾县| 申扎县| 昌平区| 湖北省| 荣昌县| 通渭县| 和田市|