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

精贴 置顶
2844 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-06-25
.NET后台写JS代码 2011-11-03
网站地址多出jdfwkey的问题解析及... 2010-08-25
数据库xxx的日志已满,请备份该数... 2013-07-19
百度、google、Yahoo网站地图制作... 2011-01-30
<a>标签的伪类书写顺序问题... 2010-09-04
什么是长尾关键词? 2010-09-24
CEO名言 2010-08-31
Mysql 主从数据库同步 2010-09-12
用ASP实现网页BBS 2010-11-01
博主推荐
本个人博客微信公众平台上线啦~~... 2013-10-13
饼哥网络互联上线啦~~要买域名空... 2013-09-20
网站title标题如何正确修改不会被... 2013-08-26
饼哥通讯录系统上线啦,欢迎大家... 2013-08-24
ASP .NET MYSQL 的简单分页 并不... 2013-08-19
网站有弹窗广告这样的站点,百度... 2013-08-17
做淘宝SEO优化需要注意的8大问题 2013-08-17
淘宝网怎么做SEO优化 2013-08-17
站长们要学习的“苍井空精神” 2013-08-17
苹果公司今日发布了iOS 7第五个开... 2013-08-07
随便看看
ASP中使用Session变量的优缺点 2010-10-25
nil和release区别 2013-06-21
.net访问Mysql一些细节问题 2013-08-19
避免系统重装遇病毒攻击的九招 2010-09-07
给FCKEDITOR添加中文字体 2012-03-31
用数据绑定实现高效率动态网页 2010-10-21
关键字也有权重吗? 2010-09-19
.net2.0邮件发送代码 2010-09-11
Asp.net 2.0 Treeview 无限级无刷... 2010-09-11
淘宝客推广的三种代码有什么区别... 2013-09-17
RSS新闻
传媒新闻
CSDN
八卦新闻
女性新闻
台湾新闻
互联网
军事-新浪博客
IT-新浪博客
汽车新闻
游戏新闻
国际新闻
国内新闻
体育新闻
我的微博
北京 上海 杭州 深圳 广州 成都