Tag: Web API

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 Web Forms Project ?

In one of the previous posts , we saw how to add the WebAPI to the existing ASP.NET MVC project. Well , the process of adding the ASP.NET Web API to the existing ASP.NET Web Forms project is still the same. You can easily do that by installing it from NuGet. Open the Package Console Manager in Visual Studio 2015 and run the following command….

How to return Json instead of XML in ASP.NET Web API ?

When you make a call to the ASP.NET Web API action method and notice this in Google Chrome browser , you would see that by default the data would be displayed in the XML format as shown in the screenshot. How to return Json instead of XML in ASP.NET Web API ? You can easily change this behavior by adding the following code in the…

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