zoukankan      html  css  js  c++  java
  • asp.net Urlrewriter在虚拟主机上的使用方法

    做法如下:打开global.asax.cs,定位到protected void Application_BeginRequest(Object sender, EventArgs e)。从方法名我想也能猜到它是做什么的。输入如下代码: 
    复制代码代码如下:

    protected void Application_BeginRequest(Object sender, EventArgs e) 

    string oldUrl = HttpContext.Current.Request.RawUrl ; 
    string pattern = @"^(.+)default/(\d+)\.aspx(\?.*)*$"; 
    string replace = "$1default.aspx?id=$2"; 
    if(Regex.IsMatch(oldUrl, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled)) 

    string newUrl = Regex.Replace(oldUrl, pattern, replace, RegexOptions.Compiled | 
    RegexOptions.IgnoreCase); 
    this.Context.RewritePath(newUrl); 



    有了上边这段代码,我访问一个类似:.../default/123.aspx 的网址,当然这个网址在我的电脑上不存在,它就会被定向到:.../default.aspx?id=123。 
  • 相关阅读:
    bzoj2467 [中山市选2010]生成树
    hdu4489 The King’s Ups and Downs
    hdu4489 The King’s Ups and Downs
    Tyvj1014(区间dp)
    Tyvj1014(区间dp)
    Tyvj1013
    Tyvj1013
    Tyvj1009
    22.引用指针
    21.引用指针
  • 原文地址:https://www.cnblogs.com/top5/p/1674718.html
Copyright © 2011-2022 走看看