What is the path to signalr hubs when using ElmahR? - asp.net-mvc-4

I am trying to add some custom functionality to ElmahR dashboard page and having some issues. I have started a new project, added ElmahR dashboard NuGet package. Configured all source applications and it is all working fine as expected.
Now I want to add some custom functionality to the dashboard page. As part of this I needed to add some UI to the dashboard page, a new Hub, JavaScript etc. The custom functionality is not related Error Logging. It is completely different. It is something we would like it to add to the dashboard page. I have added new Hub, JavaScript, HTML markups but it doesn't work as expected.
I ran into the following issues:
When i try to access /signalr/hubs, I get 404 Not found error. I searched online for this error and it usually happens if you haven't configured the Hub route. I tried to add RouteTable.Routes.MapHubs() in global.asax file. However it says that A route named 'signalr.hubs' is already in the route collection. Makes sense because I am using ElmahR and because it relies on SingalR, it would have already added it to the route collection. So what is the path to /singalr/hubs in ElmahR application? When using signalR in your standard asp.net application, the usual path to hubs is /signalr/hubs but what path is it when using ElmahR?
I am getting JavaScript error "Uncaught TypeError: Cannot read property 'client' of undefined" at the line where I am trying to access hub.client. I guess it is failing because it is not able to find the new hub that i added.
Everything works fine if I copy the hub, associated JavaScript and HTML to a different ASP.NET MVC project. For some reasons it does not work with the Project that uses ElmahR. I know there is nothing wrong with the code in Hub and JavaScript as it works fine with a standard ASP.NET MVC project. Basically all I want to do is to add a singalR hub to a project that uses ElmahR. Also I can't seem to figure out the URL path to Hubs in an application that uses ElmahR. Usually the path is /signalr/hubs
UPDATE:
After further investigation, I figured the path to hubs in ElmahR dashboard application. It is /signalr101/hubs. However when requesting this, it errors: "Uncaught Error: SignalR: JavaScript Hub Proxy generation has been disabled". It appears that ElmahR would have disabled JavaScript proxies, probably by setting DisableJavaScriptProxies property of the application's IConfigurationManager to true (https://github.com/SignalR/SignalR/pull/1222). I think because of that I am getting "Uncaught TypeError: Cannot read property 'client' of undefined in my JavaScript at the line where it is trying to access hub.client. If the JavaScript proxy is disabled, then is there any extra work I have to do in my JavaScript and Hub so that I don't get this JavaScript error.

Related

Where do I put the blazor.server.js script tag in a RazorPages app?

Right now I have it at the bottom of the _Layout.cshtml layout page that is used by every other page. The problem I'm having is that pages under the Identity area throw errors in the console when navigating to Identity pages:
POST https://localhost:5001/Identity/Account/_blazor/negotiate 404
and
blazor.server.js:1 Uncaught (in promise) Error: Cannot send data if the connection is not in the 'Connected' State.
These errors make me think I'm doing something wrong with how I enable Blazor Server in my RazorPages app.
So I'm wondering, should I only have the blazor.server.js scripts on pages that are actually using Blazor? Is there a way to make it available to Areas that putting it in the Layout seems to not do?
I believe this post answers my question:
How do I use blazor server-side inside a razor component library using areas?
By default, the SignalR service uses a relative path and was unable to find the _blazor/negotiate endpoint within an Area. The suggested code change in _Layout will make it use absolute paths and normalize to /_blazor/negotiate wherever you are in the page structure.
I know this is late but incase it help others.
I got this error when I was trying to add blazor to my existing app.
I added:
<base href="~/" />
at the end of the head tag of the _layout.cshtml file found in the shared folder.
enter image description here

How to enable offline support when using HTML5 history api

What are the best practices (and how to go about doing it) to support offline mode when using html5 history api for url rewrites?
For example, (hypothetically) I have a PWA SPA application at https://abc.xyz which has internationalization built in. So when I visit this link, the Vue router (which ideally could be any framework - vue, react, angular etc.) redirect me to https://abc.xyz/en.
This works perfectly when I am online (ofcourse, the webserver is also handling this redirect so that app works even if you directly visit the said link).
However, its a different story when I am offline. The service worker caches all resources correctly so when I visit the URL https://abc.xyz everything loads up as expected. However, now if I manually type the URL to https://abc.xyz/en, the app fails to load up.
Any pointers on how to achieve this?
Link to same question in github: https://github.com/vuejs-templates/pwa/issues/188
Yes, this is possible quite trivially with Service Workers. All you have to do is to configure the navigateFallback property of sw-precache properly. It has to point to the cached asset you want the service worker to fetch if it encounters a cache miss.
In the template you posted, you should be good to go if you configure your SWPrecache Webpack Plugin as follows:
new SWPrecacheWebpackPlugin({
...
navigateFallback: '/index.html'
...
})
Again, it is absolutely mandatory that the thing you put inside navigateFallback is cached by the Service Worker already, otherwise this will fail silently.
You can verify if everything was configured correctly by checking two things in your webpack generated service-worker.js:
the precacheConfig Array contains ['/index.html', ...]
in the fetch interceptor of the service worker (at the bottom of the file), the variable navigateFallback is set to the value you configured
If your final App is hosted in a subdirectory, for example when hosting it on Github pages, you also have to configure the stripPrefix and replacePrefix Options correctly.

How do I access RouteTable.Routes.MapHttpRoute?

I have a Web Forms app that I created a few months ago and I added a Web API controller. I tried to use the 'automatic' routing that I saw in a presentation recently, but all I got was a 404. Then I tried to add routing for the Web API controller in my Global.asax using MapHttpRoute, as I've seen in several tutorials. However, even after adding Imports System.Web.Http to the file, the project will not recognize RouteTable.Routes.MapHttpRoute() I have tried adding other namespaces and ensuring that I have all the necessary Nuget packages, but I still am unable to set up routing for the Web API controller. Does anyone have a recommendation of where to start?
If anyone has this same issue in C# read on.
I am also using a web forms app and set the routing through the Global.asax file. For me Intellisense was 100% correct and it would not build regardless. To get this to work I had to add the following using directives.
using System.Web.Http;
and
using System.Web.Routing;
Becareful not to use using System.Web.Http.Routing by accident. This wont work.
You should add the reference to System.Web.Http.WebHost assembly and make sure you have
using System.Web.Http;
Why ? MapHttpRoute is defined in two assemblies, in System.Web.Http:
public static System.Web.Http.Routing.IHttpRoute MapHttpRoute(
this System.Web.Http.HttpRouteCollection routes, string name, string routeTemplate)
Member of System.Web.Http.HttpRouteCollectionExtensions
and in System.Web.Http.WebHost
public static Route MapHttpRoute(
this RouteCollection routes, string name, string routeTemplate, object defaults);
First one is an Extension on HttpRouteCollection
Second one is an Extension on RouteCollection
So when you have a webforms app, your Routes are defined in a RouteCollection so you need the WebHost version.
Its because architecture allowing WebApi to be hosted also out of IIS. see Hosting WebApi
I found this thread, which indicates that IntelliSense apparently has a problem with this, but if you type something like the following, it will build and run:
RouteTable.Routes.MapHttpRoute("MyApi", "api/{controller}")
I've just created two new webforms apps (one using .NET 4, the other 4.5), did nothing more than add web api via nuget and it worked.
What version of ASP.NET is your app running in? If you're running ASP.NET WebForms 2.0/3.5 then it's not supported.
Here's a tutorial which demonstrates how to add Web API to your Web Forms app - http://www.asp.net/web-api/overview/creating-web-apis/using-web-api-with-aspnet-web-forms
I have the same case, I solved by creating the api controller, when you add the
api controller VS will load all required refrences.

Web API Routing - Returning 404

I have a Web API project in MVC 4 but cannot find the URL to my web service. Rather than MVC, I am actually just using the C (controller) as I'm not returning a view and my model is located in an external project.
I'm using the default route, which is api/{controller}/{id}. The name of my controller is RESTController (I know, probably wasn't the best name) and is located at ~/Controllers/RESTController.cs
Based on naming convention, it seems that my web service should be located at localhost:port/api/REST but I'm just getting a 404 resource cannot be found error (no XML representation of the object returned or anything). Is this the expected behavior without a view?
The funny thing is that I also have a SOAP API in an external project that is actually just returning the REST API result and it works as it should. Doing unit tests on my methods passes... I just can't access it from a browser. I've tried every url imaginable.
Basically...
Would there a way to debug this? (ie. Turning on ASP.NET directory listing)
Does not having a view effect what is shown in the browser?
Shouldn't the browser return an XML file representing the object?
Am I missing something obvious?
Nevermind, I'm a moron. I found the problem... At some point I accidentally drag and dropped (drug and dropped past tense?) my Global.asax file into my Views folder... therefore my routes were not getting registered.
Working as intended now.

MVC4 access and identity script/style files issue

I've posted this problem on the Identity and Access Add-in page and MVC forums, but no solution is yet forthcoming, so I thought I'd try you lot.
I have an issue where if I add Identity and Access to an MVC4 project, the requests to script and css files become unstable and often don't get served by iisexpress.
Steps to reproduce:
Create a new MVC4 project - Basic, with Razor engine
Add a controller called Home - just bare controller.
Create view Index for action Index on Home controller. Use built in layout defined in _viewStart , so includes bundled jquery and modernizr
Enable IISExpress for the application
Test this application - should work fine. refresh, reload etc, all works ok.
Next, configure Identity and Access on the application with Local development STS. Leave all as defaults.
Test application again. You should see it go through the localSTS authentication and then request the Home/Index action - at this point it tries to get the script files but these requests hang. The page is delivered, but can't render as the script files in the tag prevent it doing so until the script requests time out.
If you fire up another browser session in, say, chrome, then you can navigate to the script file and it will be downloaded on that session.
Zipped project with this state is here: https://www.dropbox.com/s/dy2bs5fh70kubp6/MvcApplication3.zip
I've used fiddler and wireshark to try and identify what is happening, but it just seems like the request to iisexpress hangs.
I've tried this on both my machines. One 64 bit, the other not.
Both VS2012 Professional V 11.0.50727.1 RTMREL, .NET framework 4.5.50709, logged in as me, an administrator on the machine, VS running as administrator
Any thoughts?
Edit: some more things I've tried:
- Using Azure STS has the same effect.
- Removing the tag that is in by default means that the script files are all accessible, seemingly all the time as required, but the Thread.CurrentPrincipal.Identity is then the generic Identity - i.e. the user is not authenticated. Adding [Authorize] attribute to my BaseController then forces the authentication with the STS as with the web.config directive, and then has the same issues with the script and css files. I was kinda hoping that this might work as removes any authentication from the root of the project to the controllers only, but alas, no joy.
And lo. It was AVG antivirus
For some reason the combination of AVG and Identity and Access addin causes this issue.
I have tried disabling various components of AVG but it seems that the only solution is to disable it entirely.
So given that, who can recommend an AV that won't interfere with development activities?