纠正我对MVC中的URL路径选择 [英] correct me on url routing in mvc

查看:89
本文介绍了纠正我对MVC中的URL路径选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我globas.asax文件我有一个寄存器路线

In my globas.asax file i have one register route

routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Authentication", action = "BigClientLogin", id    = UrlParameter.Optional } // Parameter defaults
        );

和我的行动的BigClientLogin重定向到一个名为NewLogin新动作。因此,在present我当前的URL看起来像的http://本地主机:65423 /认证/ NewLogin 。但我需要我的网址中
的http://本地主机:65423 /登录的格式。从NewLogin更改操作名称的登录是不可能的,因为我叫这个动作很多地方我的解决方案。那么,有没有在MVC中路由这方面的任何替代解决方案?或者这是不可能的,更好的将是改变我的行为叫什么名字?

and in my action "BigClientLogin" it redirects to a new action called "NewLogin". So at present my current url looks like "http://localhost:65423/Authentication/NewLogin" .But i need my url in "http://localhost:65423/Login" format. To change action name from "NewLogin" to "Login" is not possible since i called this action many places in my solution. So is there any alternative solution for this in mvc routing? or is this is not possible and better will be to change my action name?

推荐答案

一个简单的解决办法是使用ActionName属性。只是把这个动作方法

A simple solution would be using the ActionName attribute. just put this on your action method

[ActionName("Login")]
public ActionResult NewLogin(...)
{
    ...
}

这将改变只有操作名称,如果你只想路径为/登录,使用路由属性:

this would change only the Action Name, if you want only the path to be /login, use the Route attribute:

[Route("login", Name = "Login")]
public ActionResult NewLogin(...)

这篇关于纠正我对MVC中的URL路径选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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