zoukankan      html  css  js  c++  java
  • ASP.NET路由应用及IIS配置(非MVC)

    一、前后台代码:

    Global.cs:

    using System.Web.Routing;

    。。。      

    void Application_Start(object sender, EventArgs e)

            {

                // 在应用程序启动时运行的代码

                //RegisterRoutes();

                RegisterRoutes(RouteTable.Routes);

            }

            public static void RegisterRoutes(RouteCollection routes)

            {

                routes.MapPageRoute("ProductsRoute", "Products/list-{lbid}", "~/Products/ProList.aspx");

                routes.MapPageRoute("ProductsDetail", "Products/show-{id}.html", "~/Products/Show.aspx");

            }

    Default.aspx添加链接:

    <p>

        <ul>

          <li><a href="#">产品中心</a></li>

          <li>·<a href="Products/list-1">产品分类1</a></li>

          <li>·<a href="Products/list-2">产品分类2</a></li>

        </ul>

    </p>

    <p>

        <ul>

          <li><a href="Products/show-1.html">产品1</a></li>

          <li>·<a href="Products/show-2.html">产品2</a></li>

          <li>·<a href="Products/show-3.html">产品3</a></li>

        </ul>

    </p>

    ProList.aspx.cs 中接收路由参数:

    protected void Page_Load(object sender, EventArgs e)

            {

                string lbid = Page.RouteData.Values["lbid"] as string;//接收路由参数

                lblLbid.Text = "lbid="+lbid;

                //下面写业务逻辑

            }

    Products/Show.aspx 接收路由参数:

    protected void Page_Load(object sender, EventArgs e)

            {

                lblMsg.Text = "id=" + Page.RouteData.Values["id"] as string;//接收路由参数;

            }  

     效果如图:

    二、IIS部署

    如果访问html时出现 404 错误,有以下两种解决方法:

    1. 在IIS7.0中,需要把网站应用程序池中的托管管道模式设置为:集成。否则会提示 404 错误。

    2. 如果实际条件不允许设置为集成模式,则需要添加“处理应用程序映射”,需添加.html文件,使用asp.net api 处理。

  • 相关阅读:
    eclipse中集成python开发环境
    取消eclipse英文单词拼写验证
    exe所在路径
    [转]关于Megatops BinCalc RPN计算器的说明
    WinDbg 蓝屏dump分析教程
    Delphi与Windows 7下的用户账户控制(UAC)机制 及 禁用兼容性助手
    【Delphi7】 解决“程序第一次可以正常编译,但再次编译的时候会报错,必须重新打开Delphi”的问题
    解决xftp远程连接中文乱码
    创建用资源管理器打开FTP位置
    收藏夹里的js
  • 原文地址:https://www.cnblogs.com/guo2001china/p/3736585.html
Copyright © 2011-2022 走看看