c# - MVC 更改登陆页面不起作用:Options.Conventions.AddPageRoute(
问题描述
我尝试使用此命令更改我的网页 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");
}
解决方案
如果您有一个带有底层 Index.cshtml.cs 页面控制器的 Index.cshtml 文件,请向其中添加以下方法:
public class IndexModel : PageModel
{
public IActionResult OnGet()
{
return RedirectToAction("Index", "Products");
}
}
我刚刚花了几个小时试图弄清楚这个...
推荐阅读
- python - Python中的非贪婪正则表达式
- mongodb - 在 mongoDB 中查找用户之间最近的位置,其中当前用户和用户集合都有一个位置数组
- java - 使用 Selenium Java 在网页上按多个选项卡
- service-fabric-stateless - 如何重新启动 Service Fabric 应用程序
- javascript - 将对象作为变量传递
- reactjs - 如何在 react-router-dom v4.3.1 中正确分解路由到组件
- laravel - 无法仅发送 json x-www-form-urlencoded 与邮递员 seding Laravel API 端点一起工作
- wordpress - 强制 HTTPS 中断管理页面
- vba - 在 Excel 中查找已过滤的 A 列中的行数
- node.js - Nodejs/Puppeteer - 如何使用 page.evaluate