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

  • 相关阅读:
    Girls and Boys
    Kindergarten
    codevs 2822 爱在心中
    Popular Cows
    QWQ
    2488 绿豆蛙的归宿(拓扑+dp)
    P1119 灾后重建
    Mr. Frog’s Game
    Basic Data Structure
    A strange lift
  • 原文地址:https://www.cnblogs.com/tangself/p/1645062.html
Copyright © 2011-2022 走看看