一个简单的asp.net伪静态实例

精贴 置顶
1804 0

首先新建一个类,如:类名为URLRerite ,让他继承IHttpHandlerFactory接口

实际代码如下:

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.IO;

/// <summary>
/// URLRerite 的摘要说明
/// </summary>
public class URLRerite : IHttpHandlerFactory
{

    #region IHttpHandlerFactory 成员
    public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
    {
        string path = url;
        string extend = Path.GetExtension(path);
        string getFileName = Path.GetFileNameWithoutExtension(path);
        string sendpath = path.Replace(extend, ".aspx");
        string filepath = pathTranslated;
        string qurstring = "";
        if (context.Request.QueryString.Count > 0)
        {

            qurstring = context.Request.QueryString.ToString() ;
        }
        // 重写URL
        filepath = context.Server.MapPath(sendpath);
        context.RewritePath(sendpath, String.Empty, qurstring);
        return PageParser.GetCompiledPageInstance(sendpath, filepath, context);

    }

    public void ReleaseHandler(IHttpHandler handler)
    {
        //throw new Exception("The method or operation is not implemented.");
    }
    #endregion
}

最后在web.config文件中的<system.web>下面写上

<httpHandlers>
   <add verb="*" path="*.shtml" type="URLRerite"/>
  </httpHandlers>

  • 没有任何评论
今日天气 ···

···

···

···

热门排行
CSS cursor鼠标样式一览表 2012/6/25
.NET后台写JS代码 2011/11/3
网站地址多出jdfwkey的问题解析及... 2010/8/25
百度、google、Yahoo网站地图制作... 2011/1/30
数据库xxx的日志已满,请备份该数... 2013/7/19
<a>标签的伪类书写顺序问题... 2010/9/4
CEO名言 2010/8/31
什么是长尾关键词? 2010/9/24
Mysql 主从数据库同步 2010/9/12
用ASP实现网页BBS 2010/11/1
博主推荐
网站title标题如何正确修改不会被... 2013/8/26
ASP .NET MYSQL 的简单分页 并不... 2013/8/19
网站有弹窗广告这样的站点,百度... 2013/8/17
做淘宝SEO优化需要注意的8大问题 2013/8/17
淘宝网怎么做SEO优化 2013/8/17
站长们要学习的“苍井空精神” 2013/8/17
苹果公司今日发布了iOS 7第五个开... 2013/8/7
小米1刷V5系统WIFI不能连接解决办... 2013/8/1
本博客手机版上线咯!会员后台也... 2013/7/31
Win7系统环境安装配置PHP开发环境... 2013/7/29
随便看看
服务器安全:防范拒绝服务攻击妙... 2010/9/6
关系运算符 2010/10/18
如何将无效的URL重定向到其他页面... 2010/9/26
Asp编码优化技巧8则 2010/10/21
让你电脑C盘快起来,揪出占据硬盘... 2010/9/7
外链发布最有效最俗的方法 2010/10/11
清除SQL被注入恶意病毒代码的语句... 2010/9/3
淘宝新浪联手合作,微博淘宝版将... 2013/7/14
nofollow属性的介绍和使用 2010/9/8
如何设置首选域? 2010/9/23
北京 上海 杭州 深圳 广州 成都