Try our conversational search powered by Generative AI!

Custom route go to home controller in addition to correct controller

Vote:
 

I've got a route which reponds to searchkeyword and page on a url e.g.

searchpage/searchkeyword/1

will go to the search page, search for the searchkeyword and display the 2nd page of results. I've used the following route

            routes.MapEnterpriseRoutes(
                name: "Search",
                url: "{language}/{node}/{searchTerm}/{page}/{action}",
                defaults:
                    new
                    {
                        controller = "Search",
                        action = "Index",
                        searchTerm = UrlParameter.Optional,
                        page = UrlParameter.Optional
                    }
                );

    but every time I go to a page it will also fire up the index method on the home controller. The home controlle ris nothing special other than it servers out the root page of the site.

Does anyome know why it is doing that and how I can stop it

Many Thanks for any all help

 

#80891
Feb 04, 2014 14:01
Vote:
 

Hi,

I had the same problem. I my case I solved it by making sure that the Index methods in the controller reflected that searchTerm and page parameters are both optional. Typically:

// search page - no query
public ActionResult Index(SearchPage currentPage) 

// search query with query
[HttpPost]
public ActionResult Index(SearchPage currentPage, string searchTerm, int? page)

    

#80899
Feb 04, 2014 15:21
Vote:
 

Thanks for your comment. Unfortunately both the searchTerm and page are optional so that hasn't corrected the issue.

Thank you though

#80938
Feb 05, 2014 12:10
Vote:
 

Actually sorted this out. The home controller request was caused by a request to the favicon. Add this to the routing init module causes this to be igonore. Problem goes away

routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

    

#80986
Feb 06, 2014 14:09
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.