How to specify url mappings in ASP.NET 4.0 when parameters are involved?

后端 未结 2 1988
时光取名叫无心
时光取名叫无心 2021-01-25 17:12

The problem

I have a web site with some articles inside. Articles are accessed using a database writing results on a single page. When a certain article is to be access

2条回答
  •  半阙折子戏
    2021-01-25 17:38

    I think you should use:

    1. ASP.NET Routing

    Eg.:

    protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }
    
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("Articles",
            "articles/{article-id}/",
            "~/Articles.aspx");
    }
    

    & on "Articles.aspx.cs" you can get the "article-id" using:

    string article-id = Page.RouteData.Values["article-id"] as string;
    
    1. Using the URL Rewrite Module

    enter image description here


    1. urlrewriter.net

    enter image description here

提交回复
热议问题