void Application_Start(object sender, EventArgs e)
    {
        // 在应用程序启动时运行的代码
               RegisterRoutes();
    }

    // 页面存放目录
    private readonly string[] _pageMapPath = { @"~/OrderManager/" };
    /// <summary>
    /// 注册路由
    /// </summary>
    private void RegisterRoutes()
    {

        var defaults = new RouteValueDictionary { { "name", "a" }, { "id", @"\d+" } };

        RouteTable.Routes.Add("OrderList1",
                              new Route("OrderList/{id}.html", defaults, new CustomRouteHandler("~/OrderList/OrderList.aspx")));

        //var defaults = new RouteValueDictionary { { "name", "1" }, { "id", 2 } };

        //RouteTable.Routes.Add("home1",
        //                      new Route("home_{Id}_{name}.html", defaults, new CustomRouteHandler("~/Index.aspx")));

        RouteTable.Routes.Add("home",
                          new Route("home",
                                    new CustomRouteHandler("~/Index.aspx")));
        RouteTable.Routes.Add("home.html",
                           new Route("home.html",
                                     new CustomRouteHandler("~/Index.aspx")));
        RouteTable.Routes.Add("index",
                             new Route("index",
                                       new CustomRouteHandler("~/Index.aspx")));
        //将Index.html请求映射为Default.aspx
        RouteTable.Routes.Add("Index-1",
                              new Route("Index.html",
                                        new CustomRouteHandler("~/Index.aspx")));

        // 将About.html请求映射为About.aspx
        RouteTable.Routes.Add("login",
                              new Route("login",
                                        new CustomRouteHandler("~/login.aspx")));
        // 将About.html请求映射为About.aspx
        RouteTable.Routes.Add("login.html",
                              new Route("login.html",
                                        new CustomRouteHandler("~/login.aspx")));
        RouteTable.Routes.Add("login.shtml",
                            new Route("login.shtml",
                                      new CustomRouteHandler("~/login.aspx")));

        // 遍历页面存放目录,为每个.aspx页面添加路由映射
        foreach (string mapPth in _pageMapPath)
        {
            string path = Server.MapPath(mapPth);
            var directoryInfo = new System.IO.DirectoryInfo(path);
            foreach (System.IO.FileInfo f in directoryInfo.GetFiles())
            {
                string fileName = f.Name;
                if (fileName.EndsWith(".aspx"))
                {
                    string routeName = fileName.Substring(0, fileName.Length - 5);
                    string url = string.Concat(mapPth.Substring(2), routeName, ".html");
                    RouteTable.Routes.Add(routeName,
                                          new Route(url,
                                                    new CustomRouteHandler(string.Concat(mapPth, fileName))));
                }
            }
        }
    }

asp.net URL重新实例的更多相关文章

  1. asp.net URL传递中文参数System.Web.HttpUtility.UrlEncode与Server.UrlEncode的区别

    asp.net URL传递中文参数System.Web.HttpUtility.UrlEncode与Server.UrlEncode的区别(一) HttpUtility.UrlEncode 方法: 对 ...

  2. asp.net url重写相关技术问题整理

    1.IIS7配置URL重写需要注意系统是32位还是64位的 在IIS7配置URL重写的时候,需要添加“脚本映射”,如果是64位系统,会有两个地方存放.net framework分别是32位系统和64位 ...

  3. ASP.NET URL伪静态重写实现方法

    ASP.NET URL伪静态重写实现方法 首先说下,ASP.NET URL伪静态只是将~/a_1.html指向到了~/a.aspx?ID=1,但a.aspx还是真实存在的,你不用./a_1.html来 ...

  4. ASP.NET导出word实例

    ASP.NET导出word实例 最近遇到一个题目就是如何在asp.net中将数据导出到word中,由于数据是动态的,所以需要在后台拼出想要的的格式,翻遍了网页找出了一个比较满意的代码,感谢那位高手.代 ...

  5. asp 获取url 返回值 和 对json 返回值的处理

    Function GetHttpPage(HttpUrl,endoce) If endoce = "" Then endoce = "GB2312" If Is ...

  6. 很不错的NGINX URL重写实例

    转自:http://www.jbxue.com/article/2187.html 本文介绍nginx URL重写的相关知识,包括301重定向的内容等,希望对大家有所帮助. nginx rewrite ...

  7. 《Entity Framework 6 Recipes》中文翻译系列 (21) -----第四章 ASP.NET MVC中使用实体框架之在页面中创建查询和使用ASP.NET URL路由过虑

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 4.2. 构建一个搜索查询 搜索数据是几乎所有应用的一个基本功能.它一般是动态的,因 ...

  8. 【记录】ASP.NET URL 特殊字符

    终极版 URL 编码,使用 Uri.EscapeDataString: string url = "C++ C#"; Console.WriteLine(Uri.EscapeDat ...

  9. ASP.NET Ajax 简单实例

    本实例讲解Ajax 调用WCF服务. 1.建立一个网站,并在其中添加一个WCF服务(这里需要选择Ajax-Enabled WCF Service). 2.IDE会自动生成一个SVC文件. 3.服务代码 ...

随机推荐

  1. POJ 3304 Segments[直线与线段相交]

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13514   Accepted: 4331 Descrip ...

  2. 前端系列之JavaScript基础知识概述

    ​微信公众号:compassblog 欢迎关注,欢迎转发,互相学习,共同进步! 有任何问题,请后台留言联系! 1.什么是JavaScript (1).JavaScript是web上一种功能强大的编程语 ...

  3. 【模板小程序】求第n个fibonacci数

    //fibonacci,find the nth num. 1 1 2 3 5 8... #include <iostream> using namespace std; int fib( ...

  4. 使用IntelliJ IDEA(PHPStorm)和xdebug在firefox、chrome中远程调试PHP

    很多PHP程序员都习惯于使用echo.var_dump和exit来中断和调试web应用程序,本文主要介绍结合xdebug.IntelliJ IDEA.Firefox/chrome/IE来远程调试PHP ...

  5. flex 布局 input 宽度不自适应

    flex 布局 input 宽度不自适应 解决方法: 给 input 加上min-height 解决!

  6. qt 移植到开发板

    一.准备工作: 1.QT应用程序 2.工具链--->交叉工具链一安装,就会有标准的c库 3.扩展的第三方库(ARM)()触摸屏库(tslib.tar.gz) 4.QT库 二.使用交叉工具链编译t ...

  7. hibernate监听器的应用

    这里是我看到的一个hibernate监听器的简单实现供参考  http://www.360doc.com/content/14/0623/11/8072791_389034447.shtml 设计思路 ...

  8. Install Centrifugo and quick start

    Install Centrifugo and quick start Go is a perfect language - it gives developers an opportunity to ...

  9. 在Windows下为PHP5.5安装redis扩展

    使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本   根据PHP版本号,编译器版本号和CPU架构, 选择php_redis-2.2.5-5.5-ts-vc11-x86.zip和ph ...

  10. python自动化--语言基础1--数据类型及类型转换

    Python中核心的数据类型有哪些?变量(数字.字符串.元组.列表.字典) 什么是数据的不可变性?哪些数据类型具有不可变性数据的不可变是指数据不可更改,比如: a = ("abc" ...