【问题标题】:How to do custom routing in asp.net core 2.1 identity ui?如何在 asp.net core 2.1 身份 ui 中进行自定义路由?
【发布时间】:2018-08-21 09:49:48
【问题描述】:

当我添加路线“/Poster/animals_institute/animals_in_trees/research_about_frogs_in_trees”并使用以下代码重定向到“仪表板”页面时,它工作正常。

public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
    .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
    .AddRazorPagesOptions(options =>
{
    options.Conventions.AuthorizePage("/Dashboard");
    options.Conventions.AddPageRoute("/Dashboard", "/Game/animals_institute/animals_in_trees/research_about_frogs_in_trees");
});
}

但这是静态路由,我需要用动态路由更改它并在 .cs 文件中访问这些路由值。喜欢的路线可以如下:

/Game/animals_institute/animals_in_trees/research_about_frogs_in_trees
/Game/birds_institute/birds_on_trees/research_about_dove
/Game/animals_institute/know/know_about_cat_in_trees
/Game/animals_institute/show/show_cat_results
/Game/men_institute/men_in_society/know_about_man_in_hospital

如何在 asp.net core 2.1 身份界面中进行这种类型的自定义路由

【问题讨论】:

  • 您可以使用RouteBuilder docs.microsoft.com/en-us/aspnet/core/fundamentals/…进行管理
  • @NileshVishwakarma:我的应用程序中没有控制器和操作方法,我只有 .cshtml 和 .cshtml.cs 页面。你有什么想法吗?
  • @Manjt,不知道。但可能这个链接对你有帮助 docs.microsoft.com/en-us/aspnet/core/razor-pages/… 。检查“模型约定”、“页面路由操作约定”主题
  • 是否要将您提供的所有 URL 路由到同一个页面?
  • 是的@KirkLarkin。但我成功地实现了这个功能。你可以查看这个问题的答案。

标签: c# asp.net-core asp.net-identity mvcrazor


【解决方案1】:

只需使用 AddPageRoute 方法添加路由,如下代码:

options.Conventions.AddPageRoute("/Game", "/Game/{client}/{event}/{title}");

您可以传递任何链接,例如 "http://localhost:64643/Game/animals_institute/animals_in_trees/research_about_frogs_in_trees" 要么 "http://localhost:64643//Game/birds_institute/birds_on_trees/research_about_dove"

【讨论】:

    猜你喜欢
    • 2018-11-13
    • 1970-01-01
    • 2018-12-04
    • 2020-07-24
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    相关资源
    最近更新 更多