You can probably solve this using Route
. I did a simple demo that you can try in just a couple of minutes. In the Global.asax.cs
file, add this method:
void RegisterRoutes(RouteCollection routes) { routes.MapPageRoute("Products", "Products/{product}", "~/getstring.aspx", false, new RouteValueDictionary { { "product", "NoneSelected" } } ); }
In the same file, in the existing void Application_Start(object sender, EventArgs e)
method, add RegisterRoutes(RouteTable.Routes);
:
void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); }
In doing so, you configured Route
, which will accept the request as follows:
http://foo.com/Products/bike%20stand
and map it to getstring.aspx
. Please note that my url encoded the space in the url.
In getstring.aspx
you can access the value ("bike stand") as follows:
protected void Page_Load(object sender, EventArgs e) { string routeValue = ""; if (RouteData.Values.ContainsKey("product")) routeValue = RouteData.Values["product"].ToString();
I installed Route
in this example on the Products path under the application folder. I do not recommend setting up the route directly in the application folder, as in the question. You can do this though if you absolutely want to:
void RegisterRoutes(RouteCollection routes) { routes.MapPageRoute("Products", "{product}", "~/getstring.aspx", false, new RouteValueDictionary { { "product", "NoneSelected" } } ); }