I tried changing the landing page of my web page mvc application using this command.
I received this error below. How would I resolve it?
public void Configure(IServiceCollection services, IApplicationBuilder app, IHostingEnvironment env)
{
app.AddMvc().AddRazorPagesOptions(options =>
{
options.Conventions.AddPageRoute("/Products/Index", "");
});
Error:
InvalidOperationException: No service for type 'Microsoft.Extensions.DependencyInjection.IServiceCollection' has been registered.
Add a ConfigureServices
method in order to configure services and DI:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddRazorPagesOptions(options =>
{
options.Conventions.AddPageRoute("/Products/Index", "");
});
}
The Configure
method should be used to configure the HTTP pipeline (ie app.UseMvc();
)
For further read, see App startup in ASP.NET Core
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.