Search code examples
javascriptasp.net-mvc-4nlogjsnlog

Unable to implement JSNLog to ASP.NET MVC solution


After I installed and referenced the JSNLog package into my MVC project, I'm experiencing an error when ever I click a link.

For example,

<a href="@Url.Action("Bar", "Foo")">Link</a>

usually produce

<a href="/Foo/Bar">Link</a>

but after I start using the JSNLog, it now produce

<a href="/jsnlog.logger?action=Bar&controller=Foo">Link</a>

which will direct to a link

http://localhost:51745/jsnlog.logger?action=Bar&controller=Foo

which shows

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

I believe JSNLog is trying to send back a exception or log event back to the server whenever it has a chance to access the server.
Am I missing something to make this functional?


Solution

  • This is actually caused by the Ignore route they inject in App_Start, moving it into your routes collection manually fixes the issue. It happens because you don't manually define routes for the rest of the controllers, so .net tries to resolve to the first one it finds defined.

    In App_Start\JSNLogConfig.cs take out

    RouteTable.Routes.Insert(0, new Route("jsnlog.logger/{*pathInfo}", new StopRoutingHandler()));

    In RouteConfig.cs add

    routes.IgnoreRoute("jsnlog.logger/{*pathInfo}");

    And all your other routes should start working fine.