开发者

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.Ig开发者_如何学CnoreRoute("{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??


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜