I have written a simple web API in the existing asp.net webforms project and published it on HostGator shared hosting.
API was working fine locally but not accessible after hosting.
Process how I created this API in My web forms project.
Step 1. I added a new Web API controller class to my Webform project by
right-click on webform project ->Add->Web API Controller class.
Step 2 .Added some routing information to Application_Start () methof of global.asax file .
- GlobalConfiguration.Configure(WebApiConfig.Register);
- public static class WebApiConfig
- {
- public static void Register(HttpConfiguration config)
- {
-
-
- config.MapHttpAttributeRoutes();
- config.Routes.MapHttpRoute(
- name: "DefaultApi",
- routeTemplate: "api/{controller}/{id}",
- defaults: new { action = "GetRadarData", id = System.Web.Http.RouteParameter.Optional }
- );
- }
- }
Step 3: Adding code to the controller class for Get method.
- public IEnumerable<clsRadarInfoEnt> GetRadarData(string userId, string password)
- {
- string Response = "";
- clsLibrary.mGetRadarList(userId, password, out RadarList, out Response);
- if (RadarList == null && Response == "Invalid login")
- {
- var response = new HttpResponseMessage(HttpStatusCode.NotFound)
- {
- Content = new StringContent("User doesn't exist", System.Text.Encoding.UTF8, "text/plain"),
- StatusCode = HttpStatusCode.NotFound
- };
- throw new HttpResponseException(response);
- }
- else if (RadarList == null && Response == "Incorrect password")
- {
- var response = new HttpResponseMessage(HttpStatusCode.Unauthorized)
- {
- Content = new StringContent("Incorrect Password", System.Text.Encoding.UTF8, "text/plain"),
- StatusCode = HttpStatusCode.NotFound
- };
- throw new HttpResponseException(response);
- }
- else
- {
- return RadarList;
- }
- }
It was working fine locally and giving the result as aspected but after hosting the website on Hostgator showing error
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
Please reply back.
Thank you in advance