walter
walter

Reputation: 547

asp.net mvc routedata returns me weird stuff?

Hi I'm building an asp.net mvc site

I defined a custom route

public static void RegisterRoutes(RouteCollection routes) {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{country}/{controller}/{action}/{id}", // URL with parameters
            new { country = "uk", controller = "Mobile", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    }

I have a base controller that does this

        protected override void Initialize(RequestContext requestContext) {

        foreach (var d in requestContext.RouteData.Values) {
            Debug.WriteLine(d.Key);//here key country returns me favicon.ico
            Debug.WriteLine(d.Value);
        }
        this.DBConnCountryCode = requestContext.RouteData.Values["country"].ToString() + "m";
        ViewData["country"] = this.DBConnCountryCode;
        Debug.WriteLine(ViewData["country"]);
        base.Initialize(requestContext);
    }

so basically I want to get the country code in the url such as:

http://mysite/uk/Mobile i want to get the "uk" but it returns me favicon.ico?? what is favicon.ico?? why RouteData.Values["country"] returns me favicon.ico??

Upvotes: 0

Views: 608

Answers (1)

Ben Cull
Ben Cull

Reputation: 9504

The favicon.ico is the little icon that appear to the left of your URL bar and tab. In MVC, when a browser goes looking for your favicon.ico and can't find it, you'll get some strange things happening.

Add this line of code below the other ignore route to ignore the favicon.ico request.

routes.IgnoreRoute("favicon.ico");

Upvotes: 1

Related Questions