Asp.net signalr is used to transfer the data between server
and client asynchronously and it is real time communication between server and
client.Asp.net signalr maintains persistent connection between server and
client. Using signalr we can create multiuser real time applications and chat
applications. This is typically required for the real time monitoring
applications.Signalr has Hub class to allow the client and server to call
methods each other.
The easiest way to setup signalr in mvc is using nugget package
manager.
Create sample mvc project name it as SignalRMVC=>Right
click on project and click on Manage Nuget Packages and search with signalR now
select Microsoft Asp.Net SignalR and click on install,now The SignalR will be
successfully installed in your project.
Create one folder name it as Hubs and add one class to this
folder and name it as Startup
Please write the following code in Startup class
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
The Startup class will be look like as below
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
Now run the application you will get the following error
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.
or
Cannot create/shadow copy 'WebGrease' when that file already exists.
To resolve this you need to add one key in Appsettings in
web.config
<add key="owin:AppStartup" value="SignalRMVC.Hubs.Startup" />
SignalRMVC.Hubs.Startup is
namespace of your Startup class
SignalrMVC is project name and Hubs is folder name and
Startup calss
Now the run the application it will run successfully.
To check whether Signalr install on your application or
not ,go to browser and type “http://localhost:58206/signalr/hubs”
/signalr/hubs and you will get