2

I have ASP.NET Core Web MVC application that is taking data from ASP.NET Core Web API. But there is one situation when I need to call MVC from API, when data is updated on API side.

My code in MVC Controller is

public class HomeController : Controller
{
    [HttpGet,Route("updateOverview")]
    public void GetOverview()
    {
        // some code
    }
}

and on API side I have this

             try
            {
                UriBuilder uri = new UriBuilder("https://localhost:44324/Home/updateOverview");     // mvc url
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.Uri);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            }
            catch(Exception e)
            { }

but response code is 404. Then I try this

            HttpResponseMessage responseMessage1 = await _apiClient.GetAsync("https://localhost:44324/Home/updateOverview");

but also get 404.

I also tried creating API controller on MVC side so instead of trying to hit this controller

public class HomeController : Controller
{}

I try hitting this

[Route("api/[controller]")]
[ApiController]
public class GetDataController : ControllerBase
{}

but also getting 404.

1
  • 1
    try = >> [HttpGet,Route("home/updateOverview")] Commented Feb 28, 2021 at 12:30

1 Answer 1

1

try = >>

[HttpGet,Route("home/updateOverview")]

or

[HttpGet,Route("[controller]/updateOverview")] 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.