Reputation: 4076
Here's the code for configuration in startup
public void ConfigureServices(IServiceCollection services) {
services.AddControllers();
services.AddRazorPages();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
app.UseEndpoints(endpoints => {
endpoints.MapRazorPages();
endpoints.MapControllers();
});
}
I would like to have all of the controllers mapped under '/api' and everything else maps to razor pages. I've done a ton of searching the web, but I can't seem to find what I'm looking for.
Upvotes: 7
Views: 8666
Reputation: 20116
There's no problem with your startup.cs
.If you want to map all /api
to your controller, then just decorate your api controller with attribute routing like:
[ApiController]
[Route("/api/[controller]")]
public class WeatherForecastController : ControllerBase
Then create a Pages
folder in your project where locates Razor Pages.
Upvotes: 9
Reputation: 988
Have you seen this yet?
http://www.binaryintellect.net/articles/e6557104-d06a-418c-a1a9-b8ce248f60b1.aspx
Looks like it can be done. You just won't call services.AddRazorPages();
Let me know what you see wrong with this or if it works.
Upvotes: 0