吴旭晓个人博客 繁体中文 简体中文

首页| 日志 |JAVA |ASP |PHP |Android |IOS |ASP.NET |JavaScript |DIV+CSS |SEO |taobaoke |饼哥语录
繁体中文 简体中文

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

首先新建一个类,如:类名为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>

作者:吴旭晓 | 来源:个人博客 | 点击量:2837 | 发布时间:2010-09-11
最新留言 | 返回上一页 | 返回首页

相关文章:

版权所有:吴旭晓个人博客 Copyright © 2013-2023 个人博客