Tutorial: Server Broadcast with SignalR 2 - asp.net-mvc

I read this excellent tutorial : http://www.asp.net/signalr/overview/getting-started/tutorial-server-broadcast-with-signalr.
I then downloaded the NuGet example package Microsoft.AspNet.SignalR.Sample 2.2.0 (https://www.nuget.org/packages/microsoft.aspnet.signalr.sample), and then I created new asp.net mvc 5 project with vs 2015 with an index page.
I assume that app.MapSignalR() is called in the Startup.Configuration method.
Like lots of people I got the error: ticker.client is undefined.
The real problem is the var ticker = $.connection.stockTicker, is always null because $.connection has no stockTicker property defined - because the hub can't instantiate it.
Does anybody know the reason for this error?
The orignial tutorial is http://www.asp.net/signalr/overview/getting-started/tutorial-server-broadcast-with-signalr I hosted my sample project zip to my open onedrive : https://onedrive.live.com/embed?cid=11357B31E08CCFEE&resid=11357B31E08CCFEE%21107&authkey=ALMOtmTFdCdsyV8
The "SignalR.Sample" directory content in the solution is the basic Template to integrate in asp.net mvc 4/5/6 project. So I integrate it in Views/Home/Index.cshtml page. Js refernces are in file Views/Shared/_Layout.cshtml .
Exact problem is var ticker = $.connection.stockTicker is null (no initialize connection done with the server).
If you can help me, i thank you.

Yes, you added the jQuery and Stockticker scripts in your _Layout, but you didn't add the signalr/hubs. The scripts must be loaded in this exact order:
<script src="~/Scripts/jquery.signalR-2.2.0.js"></script>
<script src="~/signalr/hubs"></script>
<script src="~/Scripts/SignalR.StockTicker.js"></script>
Reference:
ASP.NET SignalR Hubs API Guide - JavaScript Client

Make sure that the JavaScript file references in StockTicker.html are correct. That is, make sure that the jQuery version in your script tag (1.10.2 in the example) is the same as the jQuery version in your project's Scripts folder, and make sure that the SignalR version in your script tag is the same as the SignalR version in your project's Scripts folder. Change the file names in the script tags if necessary.

Make sure you have Any CPU as your active solution platform. I switched it to x64 and that made it so SignalR could not load since it had an incorrect platform.

Related

Using Razor Templates Stored in Razor Class Library 3.0 (RCL) Without AspNetCore Web Application

I am using Razor templates (cshtml) to build HTML for use in emails. While I can get this all to work and I can send email from a ASPNetCore 3.0 web application I want to actually send email from another process which is NOT a web application. Ideally I would like to queue email, which can be triggered from any number of backend processes, and then send those from a timer like service which runs as a windows service or possibly a back-end worker running in Azure via something like Functions.
Is there any way to leverage razor templates from within a RCL in a .NetCore console or other application which is NOT hosted in AspNetCore??
I think there isn't a way to do this i am sry. :(
If I understand your question correctly, you can use RazorEngine, which I used in .NET Framework 4.6.2 Class Library. There is a .Net Core Nuget as well.
I referenced such Class Library projects from Console Applications, Windows Services and Azure Cloud Services (Worker Roles).
In my setup, I had to mark Razor files as Content so they are copied over to the bin folder. Also, it got more complicated if library is referenced by another library and then that library is used; content did not get copied over or it got flattened out (all razor views ended up in the root of the bin folder vs following directory structures), for which there is a fix by editing project file and adding your own copy build tasks. Or I had to embed razor views into DLL.
There might be improvements to this in recent years, as I said I used RazorEngine few years back. And it might be different in .Net Core RCL as well, but I believe it is possible.
Nowadays, I am using 3rd party services like SendGrid or MailJet. For me, using them avoids majority of the above issues and offers better insight into emails/templates/campaigns to Marketing and other non-tech users. They can edit and modify templates to their liking without (m)any code deployments.
You have to run the code through ASP.net core engine so that Razor code get converted into html.
Otherwise use simple html template.

Where to add ES6-Promise Script Tag In ASP.net MVC?

I'm using the sample here to embed a Power BI report into a web application.
The application compiles properly, but I'm getting an error involving Promises. I've tracked down the solution here. It seems that I need to add the following somewhere in my application:
<script src="https://npmcdn.com/es6-promise#3.2.1"></script>
However, I have absolutely no idea where this script tag should go. Any suggestions? Thank you.
The es6-promise library is a polyfill for Promises, mostly used in IE.
If you need it, you just need to put it anywhere in your <head> tag, preferably before your <script src='.../powerbi.js>.
For more info on es6-promise: https://github.com/stefanpenner/es6-promise

Angular 4 ng-controllers

I am building an Asp.net website with Angular 4 and bootstrap. Being a .net developer, I would like to have all the html in the .cshtml files. Earlier I have used Angular 1.0 version and we use the ng-controller and all the services call will be made from there. Trying to find documentation on using controllers but couldn't find any? Do we have ng-controllers in Angular 4? If not whats the best alternative. Also I dont want to use "TemplateUrl" in the component to render the cshtml content. In few cases, cshtml will have dynamic content and don't want an additional http request made.
Thanks in advance.
Thats right what Usman told you. At Angular 2/4 your App structure is completly new. You got a Template which is controlled by the #Component, where is linked with the attribute: 'template: "Page.html"'. There is also the templateURL Which is also an attribute of #Component. Use this if you want to specify your templateURL in your Typescript File. And another thing: Your Scope has changed a bit so think about it if you try to call javascript code in your template.
hope it helped.
There is no ng-controllers in Angular 2/4. You have components (kind of, but not exactly, controllers in AngularJs). There is no clean way of using server side views with Angular 2/4 unless you want to use server side rendering of Javascript using nodejs.
Have a look at this post https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/
This is based on Microsoft's JavaScript services library which does server side compilation for cshtml files. Steve Sanderson has a nice post (though a bit older now) about setting up Angular with ASP.NET
hope this helps.

Determine which Kendo UI version and product I"m working with

I've started as a new dev in a team where all previous devs have left and as usual it's not easy to find information.
The project is asp.net MVC 4.
There is a reference to a dll : Kendo.Mvc.dll
The project has the following script files:
kendo.aspnetmvc.min
kendo.core.min
kendo.data.min
kendo.data.odata.min
kendo.data.xml.min
kendo.grid.min
kendo.web.min
And also includes jquery and jquery-ui (1.10).
Question:
How do I know if the product was purchased or the kind of licence this is ? (all dependencies have been put into source control, I can't find any obvious key file or something like that in the config).
How do I know which version of the product it is ? (this one I think I've got the answer, the DLL version says: 2013.2.xxx so that's probably it)
Where can I download the old versions of the scripts ?
I'm very confused about the state of those components. It seems like Telerik acquired Kendo a while ago and this project has old version.
Thanks
Yes, the DLL version is the Kendo UI version (or more precisely, the UI for ASP.NET MVC version). In more recent versions, the DLL description explicitly states if it is a trial version or not.
In addition, Kendo UI JavaScript files and CSS files have their version in a comment at the top of the file contents, e.g.
http://kendo.cdn.telerik.com/2016.3.914/styles/kendo.common.min.css
/**
* Kendo UI v2016.3.914 (http://www.telerik.com/kendo-ui)
* Copyright 2016 Telerik AD. All rights reserved.
Another possible way to check the scripts version in the web application or browser console is via kendo.version - the API docs also explains the meaning of the version number.
The DLL version should always match the version of the JavaScript and CSS files (except the last part of the DLL version, which is related to the ASP.NET MVC version).
It seems like Telerik acquired Kendo a while ago
Kendo UI has always been a product of Telerik.
It is possible to download previous versions' installers from telerik.com if you have the email for account that has held the commercial license.
you can print it in the console
<!-- Telerik KendoUI Default v2 CDN 2019 -->
<link href="https://kendo.cdn.telerik.com/2019.2.619/styles/kendo.common-empty.min.css" rel="stylesheet-disabled" />
<link href="https://kendo.cdn.telerik.com/2019.2.619/styles/kendo.rtl.min.css" rel="stylesheet-disabled" />
<link href="https://kendo.cdn.telerik.com/2019.2.619/styles/kendo.default-v2.min.css" rel="stylesheet" />
<link href="https://kendo.cdn.telerik.com/2019.2.619/styles/kendo.default-v2.mobile.min.css" rel="stylesheet-disabled" />
<!-- jQuery -->
<script src="/scripts/jquery/jquery-3.4.1.min.js"></script>
<script>
// Print jQuery, kendoUI version
$(document).ready(function(){
console.log('Detected jQuery version: %o', $().jquery);
console.log('Detected Telerik KendoUI version: %o', kendo.version);
});
</script>
The version is indeed in the DLL.
Missing scripts can be found and downloaded from cdn.kendostatic.com
Only mistery remaining is the licence... not sure it's worth investigating.

ASP.Net Web API Help Page returning empty output

I have a preexisting MVC app that I added Web API and Web API Self Documentation using Nuget. While the Web API controllers function fine (return valid responses to HTTP requests) the Help controller is not finding any Web API methods to document.
In the Help controller Index action "Configuration.Services.GetApiExplorer().ApiDescriptions" is returning with 0 results.
I even went as far as copying the entire "HelpPage" area from another functioning web app.
What populated ApiDescriptions and are there any config settings I need to set to expose my api to documentations?
Things I have tried:
Reinstalling nuget packages
Copying over HelpPage area from working project
Copying over routes from working project
Comparing references from working project to broken project
Comparing Global.asax.cs from working project to broken project
Comparing web.config's from working project to broken project
It turns out my Glimpse MVC 4 installation was interfering. This is a known issue with Glimpse and Web API Help Pages. Uninstalling Glimpse fixes the problem.
The link provided by William also provides the following work-around in this comment which worked for me:
For now, you can use a simple workaround by ignoring the RoutesInspector. Just add this to your web.config:
<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
<inspectors>
<ignoredTypes>
<add type="Glimpse.AspNet.Inspector.RoutesInspector, Glimpse.AspNet"/>
</ignoredTypes>
</inspectors>
</glimpse>

Resources