How to broadcast a message from outside SignalR hub

Broadcasting a message from SignalR hub is pretty straight forward, but sometimes you may need to do the same from outside the hub, like from MVC controller or a Web Page. This snippet will help you to broadcast messages from outside hub. var context = GlobalHost.ConnectionManager.GetHubContext<MySampleHub>(); Context.Clients.All.Notify("Notification from Server"); In...


How to use NuGet without adding packages to TFS

In the recent project I was using few nuget packages. And I was using TFS. Committing these packages into TFS was increasing the size of the repository. Later I found a solution using Enable NuGet Package Restore option. You can enable this option by right clicking on the solution file...


How to configure WebAPI always return JSON

WebAPI will return JSON or XML based on the request accept header. But some times you may need to return JSON only, without considering the accept header. Here is the code snippet which will helps to return JSON always. GlobalConfiguration.Configuration.Formatters.Clear(); GlobalConfiguration.Configuration.Formatters.Add(new JsonMediaTypeFormatter()); You need to place this code in the...


How to return anonymous types from WebAPI

Sometimes you may required to return anonymous types from your WebAPI functions; I found a situation like this today, where I need to return list of values with a count, which was using to plot some graphs. Initially I thought of creating an class for this purpose with a count...


Entity Framework Error - The underlying provider failed on Open

Yesterday while working on an ASP.Net MVC application, I got an error like this from Entity Framework Data Context. The problem started when I deployed the application in IIS server, while in the development server (IIS Express) it was working fine. In the connection string, I was using Windows Authentication....


How to enable Windows Authentication in IIS Express

Unlike IIS Server, IIS Express doesn’t support Windows Authentication by default. You can enable the Windows Authentication in IIS Express by modifying the applicationhost.config under the “C:\Users[username]\Documents\IISExpress\config” directory. You need to find the windowsAuthentication element under authentication, and change the value of attribute enabled to true. Happy Programming.


Cannot create/shadow copy 'File Name' when that file already exists

Sometimes while debugging ASP.Net applications, intermittently you may get an error like this. The .Net Framework has a feature called Shadow Copy. Shadow copy is enabled on every appdomain created by ASP.NET by default. By default assemblies loaded will be copied to a shadow copy cache directory, and will be...