从 URL mvc 中省略控制器名称 [英] Omit controller name from URL mvc

查看:23
本文介绍了从 URL mvc 中省略控制器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一些类似于这篇文章的事情:

如何在 Url 中隐藏控制器名称?

只有没有任何类型的 ID.

服务器正在运行 IIS 6,并且页面已经显示而没有扩展名,因此这不是通配符问题.

我想点击 http://website.com/action-name

我有 http://website.com/controller/action-name 工作

我假设这只是一个简单的路由更改,我不知何故搞砸了.我当前的路由规则是:

routes.MapRoute("路线名称",{行动}",新{控制器=主页",动作=索引"});

解决方案

你的新路由规则是否位于上方{controller, action, id}的默认路由规则以便它有机会匹配第一?

I'm looking to do something similar to this post:

How to hide controller name in Url?

only without any sort of ID.

The server is running IIS 6 and the pages already show up without extensions so it's not a wildcard issue.

I'm looking to hit http://website.com/action-name

I have http://website.com/controller/action-name working

I'm assuming this is just a simple routing change that I am somehow goofing up. My current routing rule is:

routes.MapRoute(
    "RouteName",
"{action}",
new { controller = "Home", action = "Index" }
);

解决方案

Is your new routing rule positioned above the default routing rule of {controller, action, id} so that it has the opportunity to match first?

这篇关于从 URL mvc 中省略控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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