Failed to serialize the response in Web API

Simplest example of this, I get a collection and try to output it via Web API: // GET api/items public IEnumerable<Item> Get() { return MyContext.Items.ToList(); } And I am getting the below error while hitting the api via Postman: This is a pretty common error to do with the new proxies, and I know that […]

Read More

IHttpActionResult vs HttpResponseMessage

In this post, we will learn the difference between IHttpActionResult and HttpResponseMessage, advantages of using the IHttpActionResult, why should we use IHttpActionResult instead of HttpResponseMessage and predefined helper methods for IHttpActionResult with examples. In web API 1, We have a type called HttpResponseMessage for returning Http response message from action method. It is easy to use […]

Read More

How to change the Action name in ASP.Net MVC

ActionName attribute can be used for changing the action name. Below is the sample code snippet to demonstrate more : [ActionName(“TestActionNew”)] public ActionResult Test() { return View(); } So in the above code snippet “Test” is the original action name and in “ActionName” attribute, name – “TestActionNew” is given. So the caller of this action […]

Read More

Implementing Basic Authentication in ASP NET Web API

In this post, we will learn to how to implement basic authentication using custom authentication filter. We will not go with  any membership technique like asp.net identity. In my previous post i have explained to implement Authentication and Authorization in Asp.Net MVC using IPrincipal interface, AuthorizeAttribute, Filters and session. But in this post i will use […]

Read More

Constructor in C#

Constructor is special method of a class that name is same as class name. Main use of constructors is to initialize private fields of the class while creating an instance for the class. Constructor is automatically invoked or called when an instance of that class is created. When you have not created a constructor in the class, the […]

Read More

How to Overload the Action Method in ASP.NET MVC

In this article, we will learn how to overload an action method in asp.net MVC with example. In Asp.Net MVC, We can overload an Action method via action name attribute . Action methods must be public because private reflection isn’t permitted in medium trust. Action methods cannot be static because all the useful properties that hang […]

Read More

NonAction Method in Asp.Net MVC

In ASP.NET MVC, every public method of controller is accessible via URL regardless of return type, so if we have created any public method in controller which is not intended to serve as action method then also it is accessible via URL. One solution is that keep this method as private or protected but some time […]

Read More

Child Action Methods in ASP.Net MVC

In this article, We will learn how to use and where to use Child Action methods. A ChildAction method is an action method which can be accessible from the View only and restricts us to access via an URL. If we try to invoke this action via an URL then it prompts us an error message. We […]

Read More