zoukankan      html  css  js  c++  java
  • 伪静态

    首先加类

    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处理

  • 相关阅读:
    过滤非GBK字符
    打印整数数字
    std::string 方法列表
    设计模式——单例模式(Singleton )
    编程之美二进制一的个数
    Jsoncpp试用指南
    GCC下宏扩展后的++i
    关于字节对齐的sizeof的讨论
    Notepad++ 更改和定制主题
    求子数组的最大和
  • 原文地址:https://www.cnblogs.com/tangself/p/1645061.html
Copyright © 2011-2022 走看看