asp.net web api methods are not getting executed

Viewed 85

I am creating a web application in asp.net mvc with jQuery, I created a mvc application and included one web api controller, now my controller looks like the below

public class DefaultController : ApiController
{
    [HttpGet]
    [Route("Default/test")]
    public string test()
    {
        return "1";
    }
}

url of the application

https://localhost:44308/Home/about

URL Image

but when I execute the method of my api the following error is coming

This site can’t be reached

web api

I tried this with ajax call also but still the same problem

$.ajax({
    type: 'GET',
    url: 'https://localhost:44308/Default/test',
    async: false,
    global: false,
    contentType: "application/json",
    success: function (returnedData) {
        console.log(returnedData)
    }
});

console

I don't understand what I did wrong here

1 Answers

Change the route attribute

    [Route("~/Default/test")]
    public string test()
    {
        return "1";
    }
Related