I’ve been trying to get some routing up and running. I basically want this url:
http://www.example.com/SomebodysName
or
http://www.example.com/agents/somebodysname
..to go to…
http://www.example.com/portfolio.aspx?ran=somebodysname
I have tried to use an example from MSDN, using globax.asax like this:
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(System.Web.Routing.RouteTable.Routes);
}
public static void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
routes.MapPageRoute("", "agents/{name}", "portfolio.aspx?ran={name}");
}
but I can’t get it to work, it says Routing does not exist in the namespace System.Web.
how can I get it to work this way or perhaps another way (web.config?)
Ensure your Global.asax has a using statement for:
You can map your route like this without the param on the target physical aspx page:
In the code-behind in portfolio.aspx.cs, you can simply refer to the
namevalue like this:This will ensure your ASP.NET 4+ site will have the URL routing working as you expect/describe.