发布到 IIS10 时未在 PageModel 中发现端点:Http Response 404 .Net Core RazorPages
Endpoints not being discovered in PageModel when Published to IIS10: Http Response 404 .Net Core RazorPages
在 IIS Express 中调试时,所有端点都可以通过 GET 访问。当发布到 IIS10 时,我可以导航到正在调用的页面 public void OnGet()
并呈现剃刀页面。在服务器 IIS10 上调用 ./MyPage/Partial 时,我收到 404 Not Found 错误,这在 Visual Studio.
中的 IIS Express 上不会发生
public class IndexModel : PageModel
{
[BindProperty]
public MyModel MyModel { get; set; }
[HttpGet]
public void OnGet()
{
...
}
[HttpGet]
public IActionResult OnGetPartial([FromQuery] int id)
{
...
}
}
我已按照 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
上的说明进行操作
尽管我的问题是为什么在 IIS Express 中我可以调用 javascript jquery $.load('./MyPage/Partial?id=1')
并且它工作正常并且在发布时 returns 出现 404 错误?以及具体的解决方案是什么?
编辑:在我的 Index.cshtml 中,我在顶部有以下 @page“{handler?}” 以处理自定义 REST 方法。
为了解决这个问题,我遵循了文件 Startup.cs 中 https://docs.microsoft.com/en-us/aspnet/core/razor-pages/razor-pages-conventions?view=aspnetcore-2.2 的说明,或者您在 Program.cs 中通过
使用的任何 class
WebHost.CreateDefaultBuilder(args)
.UseKestrel()
.UseStartup<Startup>();
在文件中的方法中Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore().AddRazorPages(options => options.Conventions.AddPageRoute("/MyPage", "/MyPage/Partial/{id}")).AddRazorViewEngine().AddViews();
// Other service code impl. here
}
在 IIS Express 中调试时,所有端点都可以通过 GET 访问。当发布到 IIS10 时,我可以导航到正在调用的页面 public void OnGet()
并呈现剃刀页面。在服务器 IIS10 上调用 ./MyPage/Partial 时,我收到 404 Not Found 错误,这在 Visual Studio.
public class IndexModel : PageModel
{
[BindProperty]
public MyModel MyModel { get; set; }
[HttpGet]
public void OnGet()
{
...
}
[HttpGet]
public IActionResult OnGetPartial([FromQuery] int id)
{
...
}
}
我已按照 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
上的说明进行操作尽管我的问题是为什么在 IIS Express 中我可以调用 javascript jquery $.load('./MyPage/Partial?id=1')
并且它工作正常并且在发布时 returns 出现 404 错误?以及具体的解决方案是什么?
编辑:在我的 Index.cshtml 中,我在顶部有以下 @page“{handler?}” 以处理自定义 REST 方法。
为了解决这个问题,我遵循了文件 Startup.cs 中 https://docs.microsoft.com/en-us/aspnet/core/razor-pages/razor-pages-conventions?view=aspnetcore-2.2 的说明,或者您在 Program.cs 中通过
使用的任何 classWebHost.CreateDefaultBuilder(args)
.UseKestrel()
.UseStartup<Startup>();
在文件中的方法中Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore().AddRazorPages(options => options.Conventions.AddPageRoute("/MyPage", "/MyPage/Partial/{id}")).AddRazorViewEngine().AddViews();
// Other service code impl. here
}