2

I have same issue as per following questions and tried answer but never resolve issue

Web api interface works locally but not on Azure

Web API interface works locally but gets 404 after deployed to Azure Website

and many more similar type of...

When i tried to call api it says 404 Not Found

my WebApi.config file

// Web API routes
        config.MapHttpAttributeRoutes();


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


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

API Controller

[Authorize]
[RequiresSSL]
[RoutePrefix("api/v2/Configuration")]
public class ConfigurationAPIv2Controller : ApiController
{
    [Dependency]
    public IConfigurationServicev2 configurationService { get; set; }

    [Dependency]
    public IAccountService accountService { get; set; }


    #region testapi

    [Route("getstring")]
    [HttpGet]
    public IHttpActionResult getstring()
    {
        return Ok("Success");
    }


    [Route("putstring")]
    [HttpPut]
    public IHttpActionResult putstring()
    {
        return Ok("Success");
    }
    #endregion

And Folder Structure is like :

enter image description here

i got follwowing issue for both get and Put method enter image description here

Ganesh Jangam
  • 97
  • 1
  • 4
  • 15

2 Answers2

1

404 error might caused by route issue. Since you are using route attribute for your Web API. Please make sure GlobalConfiguration.Configure(WebApiConfig.Register); is above other code.

protected void Application_Start()
{
    GlobalConfiguration.Configure(WebApiConfig.Register);
    AreaRegistration.RegisterAllAreas();
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

And config.MapHttpAttributeRoutes(); code is above other routes configuration.

config.MapHttpAttributeRoutes();

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

In addition, try to delete following code in your Controller to test whether it is related to the dependent injection module.

[Dependency]
public IConfigurationServicev2 configurationService { get; set; }

[Dependency]
public IAccountService accountService { get; set; }

If it also can't work for you. You could get the detail error message from web server after setting IncludeErrorDetailPolicy property in WebApiConfig class.

config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
Amor
  • 8,325
  • 2
  • 19
  • 21
  • tried as per your answer , but same issue , Header Request URL:https://XXXXXXX.azurewebsites.net/api/v2/configuration/Employee/1747 Request Method:OPTIONS Status Code:404 Not Found Remote Address:23.100.46.198:443 Referrer Policy:no-referrer-when-downgrade Even for the normal testapi controller with simple get method – Ganesh Jangam May 11 '17 at 08:50
  • [RoutePrefix("api/v2/test")] public class testapiController : ApiController { #region testapi [Route("getstring")] [HttpGet] public IHttpActionResult getstring() { return Ok("Success"); } [Route("putstring")] [HttpPut] public IHttpActionResult putstring() { return Ok("Success"); } #endregion } – Ganesh Jangam May 11 '17 at 09:02
  • clear git repo and re-push required files only and it works - as i used Continuous Deployment to Azure functionality – Ganesh Jangam May 22 '17 at 12:27
0

Visual Studio does not add a default.html page to wwwroot and IIS does.

Just add default.html page to wwwroot in your project, then re-deploy to Azure.

under
  • 2,519
  • 1
  • 21
  • 40