Preventing Cross-Site Request Forgery (CSRF) Attacks in WebAPI

CSRF is an attack which forces an end user to execute unwanted actions on a web application in which he/she is currently authenticated. With a little help of social engineering (like sending a link via email/chat), an attacker may trick the users of a web application into executing actions of...


How to execute a Stored Procedure with Entity Framework Code First

Recently I worked on a project, which I started as code first and then I forced to switch to Database first. This post is about executing procedures from EF code first.(This is an update version of this post Here is my class structure and procedures. class DatabaseContext : DbContext {...


Creating a Web API Controller with dynamic type

Most of the time while working with Web API; we were dealing with particular model from our domain and creating GET/POST/PUT/DELETE methods that map to CRUD operations. But today I faced an issue, where I need to store some data, and I don’t have a mapping class for the same....


Basic HTTP authentication in ASP.Net Web API

In this post I am going to show how to implement Basic HTTP authentication in a Web API project by customizing AuthotrizeAttribute. HTTP authentication is a standard protocol and can be easily handled by most popular client and mobile platforms. Basic authentication works as follows: - If a request requires...


How to do CSS and JavaScript Bundling and Minification in ASP.NET

ASP.NET 4.5 includes a new feature to minify and bundle CSS and JavaScript within your web application. Static content like javascript and css files contains lot of white spaces and comments. Bundling and minification improves load time by reducing the number of requests to the server and reducing the size...


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...