简体   繁体   中英

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?

创建原始帖子时存在此错误,但现在已经在几个版本中修复(我是JSNLog的作者)。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM