zoukankan      html  css  js  c++  java
  • 在asp.net WebForms中使用路由Route

    1、新建WebForms应用程序

    2、打开Global.asax文件代码如下:

    public class Global : System.Web.HttpApplication
        {
            protected void Application_Start(object sender, EventArgs e)
            {
                RegisterRoutes(RouteTable.Routes);
            }
    
            public static void RegisterRoutes(RouteCollection routes)
            {
                routes.MapPageRoute("",
                    "Test/{id}",
                    "~/Test.aspx");
            }
        }

    3、Test.aspx页面

     前台:

    <body>
        <form id="form1" runat="server">
        <div>
            <%=strId%>
        </div>
        </form>
    </body>

    后台:

    namespace WebformRouteTest
    {
        public partial class Test : System.Web.UI.Page
        {
            public string strId = string.Empty;
    
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    //strId = Request.QueryString["id"];//传统方式
                    strId = Page.RouteData.Values["id"] as string;
                }
            }
        }
    }

    4、运行结果:

    输入地址:http://localhost:50649/Test/123,结果如下图:

    输入地址 http://localhost:50649/Test.aspx?id=123 一样可以。

    本篇文章只是小测试而已,

    参考文章:https://msdn.microsoft.com/en-us/library/cc668201.aspx#adding_routes_to_a_web_forms_application

  • 相关阅读:
    [12/11/19] 折半&倍增思想学习笔记
    [11/07/19] CDQ学习笔记
    magic cube
    Codeforces Round #514 (Div. 2) B
    Codeforces Round #514 (Div. 2) C. Sequence Transformation
    八位数
    hdu3001Travelling
    Codeforces Round #512 E
    Codeforces Round #512 (Div. 2) D. Vasya and Triangle
    codeforces 1042 e
  • 原文地址:https://www.cnblogs.com/qk2014/p/5407076.html
Copyright © 2011-2022 走看看