如何在ASP.NET Core中创建自定义路由 [英] How to create custom Routing in ASP.NET Core

查看:394
本文介绍了如何在ASP.NET Core中创建自定义路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关URL重写的帮助.我是ASP.NET Core MVC的新手.当我在{param}部分中键入任何内容时,路由应将其重定向到我的控制器.

I need help with URL rewriting. I am new to ASP.NET Core MVC. When I type anything in {param} part then routing should redirect it to my controller.

因此,如果有人输入

https://mydoamin.com/ {param}

https://mydoamin.com/{param}

然后应将其重定向到该网址:

then it should be redirected to this url:

https://mydoamin.com/ {controller}/{action}/{actionurl} = {param}

https://mydoamin.com/{controller}/{action}/{actionurl}={param}

推荐答案

我找到了问题的答案.只需在您的默认路由之前在startup.cs文件中定义新的自定义路由即可.

I found the answer for my question. Just define new custom route in your startup.cs file before your default route.

routes.MapRoute(
    "Member",                                             // Route name
    "{actionURL}",                                        // URL with parameters
        new { controller = "Pages", action = "Details" }  // Parameter defaults
);

这是我的工作方式.

这篇关于如何在ASP.NET Core中创建自定义路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆