I have started a web api project and I am trying to add a new action to my existing controller. Here is my controller code and configurations:

namespace QAServices.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";

            return View();
        }

        //[Route("Home/Welcome")] I have also tried this but it doesn't work.
        public HttpResponseMessage Welcome()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            response.StatusCode = HttpStatusCode.OK;
            return response;
        }

        public ActionResult ProductPage()
        {
            return View();
        }
    }
}

RouteConfig

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

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

WebApiConfig

namespace QAServices
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.
            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            // Web API routes
            config.MapHttpAttributeRoutes();

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

When I try to run my new action I am having following error:

<Error>
    <Message>
        No HTTP resource was found that matches the request URI 'http://localhost:1095/Home/Welcome'.
    </Message>
    <MessageDetail>
        No type was found that matches the controller named 'Home'.
    </MessageDetail>
</Error>

I have followed these but can't figure out what is wrong:

Related posts

Recent Viewed