Angular C# WebAPI SignalR:- Error loading hubs. Ensure your hubs reference is correct

柔情痞子 提交于 2019-12-11 04:26:27

问题


Duplicate of Error loading hubs. Ensure your hubs reference is correct, e.g. <script src='/signalr/js'></script>

But no answer yet. Please help.


回答1:


Mine was a stupid mistake! Hope this might help others in future. I have AngularJS front end and C# Web API back end. So my routing was in Angular and Web API had a routing to make sure that angular does all the routing. So in my Global.asax file, the code was as follows

string url = Request.Url.LocalPath;
            if (!System.IO.File.Exists(Context.Server.MapPath(url)) && !url.Contains("/api/"))
                Context.RewritePath("/View/app/index.html");

I updated it as

string url = Request.Url.LocalPath;
            if (!System.IO.File.Exists(Context.Server.MapPath(url)) && !url.Contains("/api/") &&  !url.Contains("/signalr") )
                Context.RewritePath("/View/app/index.html");

Now one problem is solved.



来源:https://stackoverflow.com/questions/43730985/angular-c-sharp-webapi-signalr-error-loading-hubs-ensure-your-hubs-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!