C# MVC更改登录页不工作:Options.Conventions.AddPageRoute(

C# MVC更改登录页不工作:Options.Conventions.AddPageRoute(,c#,html,.net-core,asp.net-core-mvc,asp.net-core-2.0,C#,Html,.net Core,Asp.net Core Mvc,Asp.net Core 2.0,我尝试使用此命令更改网页Mvc应用程序的登录页。但它仍将我重定向到常规索引,而不是产品/索引。我如何解决此问题 public void ConfigureServices(IServiceCollection services) { var connection = @"Server=localhost;Database=Electronics;Trusted_Connection=True;ConnectRetryCount=0"; servi

我尝试使用此命令更改网页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");

    }
public void配置服务(IServiceCollection服务)
{
var connection=@“服务器=localhost;数据库=Electronics;可信连接=True;ConnectRetryCount=0”;
services.AddDbContext(options=>options.UseSqlServer(connection));
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.addScope(sp=>ShoppingCartSession.GetCart(sp));
services.AddSingleton();
services.AddAutoMapper();
services.AddMvc().AddRazorPagesOptions(选项=>
{
options.Conventions.AddPageRoute(“/Products/Index”,”);
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddMemoryCache();
services.AddSession();
services.AddSingleton();
services.AddSingleton(新LoggerFactory().AddConsole().AddDebug());
services.AddLogging();
_logger.LogInformation(“配置服务日志”);
}

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

public class IndexModel : PageModel
{

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

我刚刚花了几个小时试图弄明白这一点…

那么您正在更改默认的根文件夹?