Tag: ASP.NET MVC

How to accept HTML Form Data in a ASP.NET Web API Action Method ?

There are times when you might want to create an endpoint in ASP.NET WebAPI that can handle the HTML form data posted as x-www-form-urlencoded. One of the options is to use the model binding concept.   In this case , the model should have the names of the keys that are passed in the HTTP request. The MediaFormatters are used to extract the data from…

How to get the Relative Server Path in ASP.NET Web API ?

In ASP.NET MVC , we can use the Server.MapPath or Request.MapPath to get the relative path of the server for a file. For example , The fileName would be the absolute path of the file. How to get the Relative Server Path in ASP.NET Web API ? You can use the HostingEnvironment.MapPath defined in System.Web.Hosting to get the relative path of the file as shown…

How to Add Web API to existing ASP.NET MVC Project ?

There are times when you might want to add Web API project to one of your existing ASP.NET MVC project instead of creating a new one. How to Add Web API to existing ASP.NET MVC Project ? You can easily do that by installing it from NuGet. Simply open the Package Console Manager and run the following command. Install-Package Microsoft.AspNet.WebApi

How to return Http Status Code from ASP.NET Web API Controller ?

There are times when you might want to return the Http Status code from an action method of a ASP.NET Web Api Controller. One of the simplest way of doing this is using the CreateResponse method of the HttpRequestMessage as shown below. The sample below demonstrates how to return the status code 304 and 200 based on the last modified date of the employee record….