MVC更改着陆页不起作用:Options.Conventions.AddPageRoute(

问题描述 投票:2回答:1

我尝试使用此命令更改我的网页Mvc应用程序的登录页面。但是,它仍将我重定向到常规索引,而不是产品/索引。我该如何解决?

    public void ConfigureServices(IServiceCollection services)
    {

        var connection = @"Server=localhost;Database=Electronics;Trusted_Connection=True;ConnectRetryCount=0";
        services.AddDbContext<ElectronicsContext>(options => options.UseSqlServer(connection));
        services.AddTransient<IProductRepository<Product>, ProductRepository>();
        services.AddTransient<IProductCategoryRepository<ProductCategory>, ProductCategoryRepository>();
        services.AddTransient<ICustomerRepository<Customer>, CustomerRepository>();
        services.AddTransient<ISupplyRepository<Supply>, SupplyRepository>();
        services.AddScoped<ShoppingCartRepository>(sp => ShoppingCartSession.GetCart(sp));
        services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

        services.AddAutoMapper();

        services.AddMvc().AddRazorPagesOptions(options =>
        {
            options.Conventions.AddPageRoute("/Products/Index", "");
        }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

        services.AddMemoryCache();
        services.AddSession();

        services.AddSingleton<IMemoryContainer,MemoryContainer>();
        services.AddSingleton(new LoggerFactory().AddConsole().AddDebug());
        services.AddLogging();
        _logger.LogInformation("configure services log");

    }
c# html .net-core asp.net-core-mvc asp.net-core-2.0
1个回答
0
投票

如果您有一个带有基础Index.cshtml.cs页面控制器的Index.cshtml文件,请向其添加以下方法:

public class IndexModel : PageModel
{

    public IActionResult OnGet()
    {
        return RedirectToAction("Index", "Products");
    }
}

我刚刚花了数小时试图弄清楚这一点...

© www.soinside.com 2019 - 2024. All rights reserved.