首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MVC更改登录页不工作: Options.Conventions.AddPageRoute(

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

Stack Overflow用户
提问于 2019-05-16 14:37:44
回答 1查看 277关注 0票数 2

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

代码语言:javascript
复制
    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");

    }
EN

回答 1

Stack Overflow用户

发布于 2020-04-07 05:24:22

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

代码语言:javascript
复制
public class IndexModel : PageModel
{

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

我花了几个小时试图弄清楚这件事...

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56162254

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档