locked
Web API - 404 Error RRS feed

  • Question

  • User1129112648 posted

    Web API Controller:

    [EnableCors(origins: "*", headers: "*", methods: "*")]
    public class HomeController : ApiController
    {
        private  HomeDataProvider homeDataProvider = new HomeDataProvider();
    
        // GET api/<controller>
        [AllowAnonymous]
       [Route("webapi/home/get")] public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; } [AllowAnonymous] [HttpPost] //[Authorization] public List<User> Test_API(HomeSearch searchParam) { List<User> Test_User = null; try { Test_User = homeDataProvider.Test_DataProvider(searchParam); } catch (Exception ex) { throw ex; } finally { } return Test_User; }

    Web API Config

            // Web API configuration and services
    
            // Web API routes
            config.MapHttpAttributeRoutes();
    
            config.Routes.MapHttpRoute(
                name: "API Default",
                routeTemplate: "webapi/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
    

    Web API Web.config

          <appSettings></appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.5.2" />
        <httpRuntime targetFramework="4.5.2" />
            <roleManager enabled="false" />
        <!--<roleManager defaultProvider="AspNetWindowsTokenRoleProvider" 
    enabled="true" />-->
      </system.web>
      <system.webServer>
      <validation validateIntegratedModeConfiguration="false" />
      <modules runAllManagedModulesForAllRequests="true">
    </modules>
      <handlers>
       </handlers>
    
          </system.webServer>
    
    I am using windows 10, vs 2015, iis 10
    url i am calling
    http://localhost/webapi/home/get
    Error: 404, static handler error
    

    I searched and tried all options on internet and other sources but all in vain... 

    Saturday, April 8, 2017 4:30 PM

Answers

  • User1129112648 posted

    Actually: In Web API settings: i selected : Local iis, localhost/webapi... create virtual directory so my route was localhost/webapi/webapi/home/get Thanks Alex for help and probable solutions you posted...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 8, 2017 4:39 PM