Search code examples
asp.netasp.net-mvc-5asp.net-mvc-routing

ASP.Net MVC 5 Routing wildcard + querystring


I am using this Route filter

[Route("search/{*segments}")]

this takes all the segments I am providing which could be many.

Here is an example

http://localhost:50877/search/c_50_showcases%5E-displays/a_brand-name:33113319_balt:1623762%7Cmooreco:1672386/a_total-number-of-shelves:33111115429_5:3138:lt/so_ts

Now I also need the query string with this route but I am unable to make it work.

http://localhost:50877/search/?query=HP%20DesignJet&items=HEW51645A|ELI75220

It gives me 403 error.

The Web server is configured to not list the contents of this directory

How can I make a route that can take wildcard and query string to handle the incoming request. I am bound to use search in Route.

Also I tried with this

http://localhost:50877/search/test?query=HP%20DesignJet&items=HEW51645A|ELI75220

It works but this effects the SEO.


Solution

  • Defining action and route this way:

    [System.Web.Mvc.Route("search/{*segments}")]
    public ActionResult Search(string segments, string query, string items)
    

    allows to get wildcard (in segments variable) and also query string parameters (query and items)