I'm building an app ("Airport Finder" or "af" for the URL) on my personal server at home. When I run the app from VS, it works perfectly. However, when I run it through the browser, it doesn't.
The controller has two actions. The first one provides data for building the home page when it's initially displayed. That action works great. It's called as part of the razor view that returns the home page when you first hit the site.
However, the second action is returning a 404 (Not Found). It's called via AJAX after the user selects various criteria on the website. Again, this one works fine, too, if you do the search after running the website from within Visual Studio (2017). It returns the 404 if I run the site straight from the browser (although the first action returns all the initial data just fine).
I've installed the app in IIS (deployed to a folder and created an app under the default website which points at that folder).
The URL looks like this:
http://localhost/af
but the Search URL looks like this when I get the error:
http://localhost/Home/Search
I would've thought it should look like:
http://localhost/af/Home/Search
but, entering that into the browser manually just returns another 404 (Not Found).
Here's the Controller code:
public class HomeController : Controller
{
public IActionResult Index()
{
return View(Logic.GetGeneralAirportData());
}
[HttpPost]
public JsonResult Search(SearchCriteria sc)
{
SearchResults results = Logic.Search(sc);
return Json(results);
}
}
Here's the AJAX call:
$.ajax({
method: "post",
url: "/Home/Search",
dataType: "json",
data: {
...
Here's the route:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});