0
votes

i am calling one api http://169.38.100.206/sr/gsr?spn=NEWGEN-00097 which returns server error.

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /sr/gsr

My route config is

public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "AMMReport",
            url: "sr/gsr/{id}",
            defaults: new { controller = "SupervisorReport", action = "GetSupervisorReport", id = UrlParameter.Optional }
            );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Login", action = "Login", id = UrlParameter.Optional });


        }
    }

My problem is actually this api for sending one sms to client automatically ,ie like this

Hi , you have 0/19 people reporting 0 number of activities today. However 19/19 people did not report any activity and 1 was on leave .Click http://169.38.100.206/sr/gsr?spn=NEWGEN-00097 for activity report. Ineed to hide action name and controller name in url ie i have give sr and gsr.bt it didnt work. saying

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /sr/gsr

1
How is this deployed? IIS as an ASP.NET application? Shouldn't the URL include the application name?John Wu

1 Answers

0
votes

you should mentioned the api route in WebApiConfig.cs located in App_Start folder instead of App Route Config File.But if you want to call a action in custom controller you can do that without route config.just add [HttpGet]above the Method You Want to Call.But I recomend Creating a WebApi Controller to Handle all the api request in the Application.

Below should work for your question

    [HttpGet]
    public IQueryable<SupervisorList> GetSupervisorReport()
    {
        return true;
    }

Create New Api Controller

  1. Right Click on your Controllers Folder and select Add New Item
  2. From the list select Web API Controller and Click Add
  3. In the API Controller You Should Be Able to Right Your Api Methods.Mention Method Type using Annotations like [HttpGet], [HttpPost].
  4. In WebApiConfig.cs change

    config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    

to

config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{action}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );

which will enable you to create custom api methods