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

首頁 > 編程 > .NET > 正文

Global.asax的Application_BeginRequest實(shí)現(xiàn)url重寫無后綴的代碼

2024-07-10 12:44:45
字體:
供稿:網(wǎng)友
利用Global.asax的Application_BeginRequest 實(shí)現(xiàn)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>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 正蓝旗| 乌鲁木齐县| 韩城市| 怀集县| 贡觉县| 鹿泉市| 松阳县| 霍林郭勒市| 巴塘县| 都兰县| 兴文县| 内乡县| 宁国市| 霍州市| 图片| 定西市| 嘉峪关市| 达孜县| 乌兰察布市| 清流县| 台安县| 伊金霍洛旗| 大足县| 赤城县| 阿尔山市| 鹤峰县| 高邮市| 武平县| 友谊县| 漯河市| 铜鼓县| 河南省| 杭锦旗| 永登县| 阿坝县| 肇州县| 集安市| 靖江市| 察隅县| 香港| 连江县|