Daniel15 / RouteJs

JavaScript URL routing for ASP.NET MVC and WebForms
84 stars 19 forks source link

Null Reference Exception #27

Closed lalibi closed 10 years ago

lalibi commented 10 years ago

I get a Null Reference Exception, possibly due to the BrowserLink feature in the new Visual Studio (it seems route.DataTokens is null in a route generated by BrowserLink).

I downloaded the code and added a quick fix. I should probably do a pull request, but I am not entirely sure this is the proper way to solve it:

// If there's no controller specified, we need to check if it's in an area
if (!route.Defaults.ContainsKey("controller"))
{
    // Added this line here:
    if (route.DataTokens == null)
        return false;

    // Not an area, so it's a "regular" default route
    if (!route.DataTokens.ContainsKey("area"))
        return true;

    // Exposing all routes, or an area that's explicitly whitelisted
    if (_configuration.ExposeAllRoutes || _areaWhitelist.Contains(route.DataTokens["area"]))
        return true;

    // In an area that's not exposed, so this route shouldn't be exposed.
    return false;
}
lalibi commented 10 years ago

A small update, after some research. It might not be BrowserLink's fault after all but Glimpse's, and its use of Castle.Proxies.RouteProxy that causes issues.

Daniel15 commented 10 years ago

Thanks, it's probably a good idea to check if DataTokens is null before trying to use it. Do you have a small sample that replicates the issue? Please attach a ZIP with a project to replicate it :)

Daniel15 commented 10 years ago

Thanks for your bug report, I've fixed this in 1.1.5.

lalibi commented 10 years ago

Sorry for the late response. Thanks for your time.