Just like just now, do some small experiments and feel the convenience brought by the new version. Let alone other things.
Step 1:
Add Rules in the global. asax File
Void application_start (Object sender, eventargs E)
{
// Code that runs when the application starts
Registerroutes (system. Web. Routing. routetable. routes );
}
Void registerroutes (system. Web. Routing. routecollection routes)
{
Routes. mappageroute ("myfriendlyname", "Report/{year }","~ /A. aspx ");
}
Add <a href = "report/2010"> test </a> to the default. aspx page. click the button and pay attention to the address bar. Let's take a look at the content on the. ASPX page.
Public partial class A: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Response. Write (routedata. Values ["year"] as string );
If (request. querystring ["category"]! = NULL)
{
Response. Write (request. querystring ["category"]. tostring ());
}
}
}
You can also generate a friendly name by yourself:
Routevaluedictionary parameters = new routevaluedictionary ()
{
{"Year", "2008 "},
{"Category", "goods "},
{"Customer", "hello "}
};
Virtualpathdata VPD = routetable. routes. getvirtualpath (null, "myfriendlyname", parameters );
This. hyperlink1.navigateurl = VPD. virtualpath;
At this time, the address is changed to: http: // localhost: 9319/website1/report/2008? Category = Goods & customer = Hello
Let's take a look at category and customer. These two are the corresponding parameters.
It should be convenient. In the past, you also needed to configure IIS to achieve the corresponding functions.