When debugging in IIS Express all endpoints are reachable via GET. When published to IIS10 I can navigate to the page public void OnGet() is being called and renders the razor page. When calling ./MyPage/Partial on server IIS10 I receive a 404 Not Found error and this does not happen on IIS Express in Visual Studio.
public class IndexModel : PageModel
{
[BindProperty]
public MyModel MyModel { get; set; }
[HttpGet]
public void OnGet()
{
...
}
[HttpGet]
public IActionResult OnGetPartial([FromQuery] int id)
{
...
}
}
I have followed the instructions on https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.2 and my best guess is that I need to configure these routes as per https://docs.microsoft.com/en-us/aspnet/core/razor-pages/razor-pages-conventions?view=aspnetcore-2.2
Although my question is why in IIS Express I can call javascript jquery $.load('./MyPage/Partial?id=1') and it works fine and when published it returns a 404 error? And what would be the specific solution?
EDIT: in my Index.cshtml I have the following @page "{handler?}" at the top in order to handle the custom REST methods.
~/only works in Razor-parsed code. It's not an official path designator - just something Microsoft uses as shorthand for "project root". You should just use/MyPage/Partial?id=1. If you're deploying to a virtual directory, you'll need to update the URLs accordingly in production. 2) Ensure that a partial with that designator actually does exist in your production environment. In other words, you may be returning 404 based on a failed DB query, for example, rather than a bad route in general. - Chris Pratt