This article is a mirror article of machine translation, please click here to jump to the original article.

View: 21412|Reply: 1

[ASP.NET] asp.net mvc4.0 Installing SignalR (1)

[Copy link]
Posted on 7/5/2017 10:37:03 AM | | | |
According to the needs of the project, websockets should be used for data push, so SignalR should be used, because SignalR requires the .net 4.5 framework

Just right-click on the project attributes and change it to .net 4.5, and everything is normal when you run again.

nuget install:

The installation is as follows:

Package Manager console host version 4.0.0.2323
Type "get-help NuGet" to see all available NuGet commands.
PM> Install-Package Microsoft.AspNet.SignalR
Attempts are being made to collect and target ". NETFramework, Version=v4.5"WWW_ITSVSE_COM. Web "Dependency information about the package "Microsoft.AspNet.SignalR.2.2.2"
It took 24.53 sec to collect dependency information
Trying to resolve dependencies of package "Microsoft.AspNet.SignalR.2.2.2" with DependencyBehavior as "Lowest"
One or more unresolved package dependency constraints are detected in the existing packages.config file. All dependency constraints must be resolved to add or update packages. This message can be ignored if these packages are being updated, and if they are not updated, the error may prevent the current package operation: 'DotNetOpenAuth.Core 4.1.4.12333 Constraints: Microsoft.Net.Http', 'Microsoft.AspNet.WebApi.Client 4.0.20710 Constraints: Microsoft.Net.Http (>=). 2.0.20710 && < 2.1.0)', 'Microsoft.AspNet.WebApi.OData 4.0.0 constraints: Microsoft.Net.Http (>= 2.0.20710 && < 2.1.0)'
Parsing dependency information takes 0 ms
Parsing operation to install package "Microsoft.AspNet.SignalR.2.2.2"
Resolved operation to install package "Microsoft.AspNet.SignalR.2.2.2"
Retrieve package "Microsoft.AspNet.SignalR 2.2.2" from "nuget.org"
Retrieve package "Microsoft.AspNet.SignalR.Core 2.2.2" from "nuget.org"
Retrieve package "Microsoft.AspNet.SignalR.JS 2.2.2" from "nuget.org"
Retrieve package "Microsoft.AspNet.SignalR.SystemWeb 2.2.2" from "nuget.org"
Retrieve package "Microsoft.Owin 2.1.0" from "nuget.org"
Retrieve package "Microsoft.Owin.Host.SystemWeb 2.1.0" from "nuget.org"
Retrieve package "Microsoft.Owin.Security 2.1.0" from "nuget.org"
Retrieve package "Owin 1.0.0" from "nuget.org"
  GET https://api.nuget.org/packages/microsoft.aspnet.signalr.systemweb.2.2.2.nupkg
  GET https://api.nuget.org/packages/microsoft.owin.2.1.0.nupkg
  GET https://api.nuget.org/packages/microsoft.aspnet.signalr.core.2.2.2.nupkg
  GET https://api.nuget.org/packages/microsoft.aspnet.signalr.2.2.2.nupkg
  GET https://api.nuget.org/packages/microsoft.aspnet.signalr.js.2.2.2.nupkg
  GET https://api.nuget.org/packages/microsoft.owin.security.2.1.0.nupkg
  GET https://api.nuget.org/packages/microsoft.owin.host.systemweb.2.1.0.nupkg
  GET https://api.nuget.org/packages/owin.1.0.0.nupkg
  OK https://api.nuget.org/packages/microsoft.aspnet.signalr.systemweb.2.2.2.nupkg 150 ms
  OK https://api.nuget.org/packages/microsoft.aspnet.signalr.core.2.2.2.nupkg 152 ms
Microsoft.AspNet.SignalR.SystemWeb 2.2.2 is being installed.
Microsoft.AspNet.SignalR.Core 2.2.2 is being installed.
  OK https://api.nuget.org/packages/microsoft.owin.2.1.0.nupkg 436 ms
Microsoft.Owin 2.1.0 is being installed.
  OK https://api.nuget.org/packages/microsoft.aspnet.signalr.js.2.2.2.nupkg 3705 ms
Microsoft.AspNet.SignalR.JS 2.2.2 is being installed.
  OK https://api.nuget.org/packages/microsoft.aspnet.signalr.2.2.2.nupkg 4080 ms
Microsoft.AspNet.SignalR 2.2.2 is being installed.
  OK https://api.nuget.org/packages/microsoft.owin.security.2.1.0.nupkg 4080 ms
Microsoft.Owin.Security 2.1.0 is being installed.
  OK https://api.nuget.org/packages/microsoft.owin.host.systemweb.2.1.0.nupkg 4294 ms
Microsoft.Owin.Host.SystemWeb 2.1.0 is being installed.
Adding package "Microsoft.AspNet.SignalR.JS.2.2.2" to folder "C:\project\company\WWW_ITSVSE_COM\packages"
Package "Microsoft.AspNet.SignalR.JS.2.2.2" has been added to folder "C:\project\company\WWW_ITSVSE_COM\packages"
Added package "Microsoft.AspNet.SignalR.JS.2.2.2" to "packages.config"
"Microsoft.AspNet.SignalR.JS 2.2.2" has been successfully installed to WWW_ITSVSE_COM. Web
  OK https://api.nuget.org/packages/owin.1.0.0.nupkg 6801 milliseconds
Owin 1.0.0 is being installed.
Adding package "Owin.1.0.0" to folder "C:\project\company\WWW_ITSVSE_COM\packages"
Package "Owin.1.0.0" has been added to the folder "C:\project\company\WWW_ITSVSE_COM\packages"
Package "Owin.1.0.0" has been added to "packages.config"
"Owin 1.0.0" has been successfully installed to WWW_ITSVSE_COM. Web
Adding package "Microsoft.Owin.2.1.0" to folder "C:\project\company\WWW_ITSVSE_COM\packages"
Package "Microsoft.Owin.2.1.0" has been added to the folder "C:\project\company\WWW_ITSVSE_COM\packages"
Added package "Microsoft.Owin.2.1.0" to "packages.config"
"Microsoft.Owin 2.1.0" has been successfully installed to WWW_ITSVSE_COM. Web
Adding package "Microsoft.Owin.Host.SystemWeb.2.1.0" to folder "C:\project\company\WWW_ITSVSE_COM\packages"
Package "Microsoft.Owin.Host.SystemWeb.2.1.0" has been added to folder "C:\project\company\WWW_ITSVSE_COM\packages"
Added package "Microsoft.Owin.Host.SystemWeb.2.1.0" to "packages.config"
"Microsoft.Owin.Host.SystemWeb 2.1.0" has been successfully installed to WWW_ITSVSE_COM. Web
Adding package "Microsoft.Owin.Security.2.1.0" to folder "C:\project\company\WWW_ITSVSE_COM\packages"
Package "Microsoft.Owin.Security.2.1.0" has been added to the folder "C:\project\company\WWW_ITSVSE_COM\packages"
Added package "Microsoft.Owin.Security.2.1.0" to "packages.config"
"Microsoft.Owin.Security 2.1.0" has been successfully installed to WWW_ITSVSE_COM. Web
Adding package "Microsoft.AspNet.SignalR.Core.2.2.2" to folder "C:\project\company\WWW_ITSVSE_COM\packages"
Package "Microsoft.AspNet.SignalR.Core.2.2.2" has been added to the folder "C:\project\company\WWW_ITSVSE_COM\packages"
Added package "Microsoft.AspNet.SignalR.Core.2.2.2" to packages.config
"Microsoft.AspNet.SignalR.Core 2.2.2" has been successfully installed to WWW_ITSVSE_COM. Web
Adding package "Microsoft.AspNet.SignalR.SystemWeb.2.2.2" to folder "C:\project\company\WWW_ITSVSE_COM\packages"
Package "Microsoft.AspNet.SignalR.SystemWeb.2.2.2" has been added to folder "C:\project\company\WWW_ITSVSE_COM\packages"
Added package "Microsoft.AspNet.SignalR.SystemWeb.2.2.2" to "packages.config"
"Microsoft.AspNet.SignalR.SystemWeb 2.2.2" has been successfully installed to WWW_ITSVSE_COM. Web
Adding package "Microsoft.AspNet.SignalR.2.2.2" to folder "C:\project\company\WWW_ITSVSE_COM\packages"
Package "Microsoft.AspNet.SignalR.2.2.2" has been added to the folder "C:\project\company\WWW_ITSVSE_COM\packages"
Package "Microsoft.AspNet.SignalR.2.2.2" has been added to "packages.config"
"Microsoft.AspNet.SignalR 2.2.2" has been successfully installed to WWW_ITSVSE_COM. Web
The nuget operation took 18.26 sec
Time Elapsed: 00:00:45.5513744
PM>

Now that SignalR is installed, how do I register? For example, our controller or something, and then, I think of Global.asax.cs files,

Baidu took a look and found that the registration order was as follows:



An error is found with the following error:

Error CS0619 "SignalRRouteExtensions.MapHubs(RouteCollection)" is deprecated: "Use IAppBuilder.MapSignalR in an Owin Startup class. See http://go.microsoft.com/fwlink/?LinkId=320578 for more details.”        WWW_ITSVSE_COM. Web        C:\project\company\WWW_ITSVSE_COM\WWW_ITSVSE_COM. Web\Global.asax.cs 30 active

Versions of SignalR, starting from 1.2.2 and including 2.0 and above, are all started using OWIN middleware.


So, after installing signalR2.0 with nuget,Do not start the route in the application_start of Globalaxac


Instead, you should build a Startup class as the startup class.


Then, we create a new Startup class under the project root directory, and the code is as follows:

XXX represents our project name, and then, restart, it is found that no error is reported!!!

In fact, if we don't create a new Startup class, the following error will be reported after starting, which I only found out later.



The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- No assembly found containing a Startup or [AssemblyName]. Startup class.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.





Previous:Introduction and introduction to SignalR
Next:mvc 4.0 How to use SignalR (2)
 Landlord| Posted on 7/7/2017 2:28:07 PM |
mvc 4.0 How to use SignalR (2)
http://www.itsvse.com/thread-3838-1-1.html
(Source: Architect)
SignalR for websocket communication (3)
http://www.itsvse.com/thread-3845-1-1.html
(Source: Architect)


Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com