伪静态

首先加类

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Norco.DAL;

 

/

    /// <summary>
    /// Summary description  for UrlRewriter
    /// </summary>
    public class SupportWJ : IHttpHandler
    {
        public SupportWJ()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public void ProcessRequest(HttpContext Context)
        {
            try
            {
                //取得原始URL屏蔽掉参数
                string Url = Context.Request.RawUrl;
                //建立正则表达式
                //string sql = "insert into test(TestName) values(@test)";
                //SqlParameter tmp = new SqlParameter("@test", SqlDbType.NVarChar, 2500);
                //tmp.Value = Url;

                //DbAccess.SQLExecuteNoneQuery(sql, tmp);
                System.Text.RegularExpressions.Regex Reg = new System.Text.RegularExpressions.Regex(@"/NORCO-Support-(\d+)\.shtml", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                //用正则表达式进行匹配
                System.Text.RegularExpressions.Match m = Reg.Match(Url, Url.LastIndexOf("/NORCO-Support-"));//从最后一个“/”开始匹配

                //String RealPath = @"/about.aspx?id=" + m.Groups[1];

              

                if (m.Success)//匹配成功
                {
                    String RealPath = @"/Servers.aspx?sid=" + m.Groups[1];

                    //string sql = "insert into test(TestName) values(@test)";
                    //SqlParameter tmp = new SqlParameter("@test", SqlDbType.NVarChar, 50);
                    //tmp.Value = RealPath;


                    //DbAccess.SQLExecuteNoneQuery(sql, tmp);


                    //Context.Response.Write(RealPath);
                    //Context.RewritePath(RealPath);//(RewritePath 用在无 Cookie 会话状态中。)
                    Context.Server.Execute(RealPath);
                }
                else
                {
                    Context.Response.Write("404 ERROR!");
                }
            }
            catch
            {
                Context.Response.Redirect(Context.Request.Url.ToString());
            }
        }
        /**/
        /// <summary>
        /// 实现“IHttpHandler”接口所必须的成员
        /// </summary>
        /// <value></value>
        /// Author:yoyo
        /// blog:http://yangmingsheng.cn
        public bool IsReusable
        {
            get { return false; }
        }

    }

 

 

 

其次在web.config加

<add verb="GET" path="*/NORCO-Support-*.shtml" type="SupportWJ"/>

其次,配置加对shtml后缀的类ASPX处理

 

posted @ 2010-01-12 13:57  tangself  阅读(146)  评论(0编辑  收藏  举报