MVC 3保持短网址 [英] MVC 3 keeping short url

查看:150
本文介绍了MVC 3保持短网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我MVC3应用程序,在这里我想保持短网址。什么是做到这一点的最好还是干净的方式?
 可以说我有两个控制器帐户和家庭。我所有的帐户相关任务登录,注销,档案,常见问题等在账户控制器。所有家居控制器一样TASKA,TaskB和TaskC的主要任务。我要寻找的URL,如下:

I have MVC3 application, where I want to keep short URL. what is the best or clean way to do this? Lets say I have two controllers Account and Home. I have all the account related tasks Logon, Logoff, Profile, FAQs etc. in Account controller. All the main tasks in home controller like TaskA, TaskB, and TaskC. I am looking for URL as below:


  1. www.mydomain.com/Logon

  2. www.mydomain.com/Logoff

  3. www.mydomain.com/Profile

  4. www.mydomain.com/FAQs

  5. www.mydomain.com/TaskA

  6. www.mydomain.com/TaskB

当用户第一次来到他们需要重定向到登录页面的网站。在任何时候,用户也可以从一次控制器动作切换到另一个控制器动作(从TASKA到注销)。

when user first come to the website they need to redirect to Logon page. At any time user should also able to switch from once controller action to another controller action (from TaskA to Logoff).

什么是干净的方式做到这一点?

what is the clean way to do this?

推荐答案

您不需要设置一个路由每个URL。从路由约束一点帮助,你可以做这样的事情:

You don't need to set a route for each URL. With a little help from route constraints you can do something like this:

        routes.MapRoute(
            "Home", // Route name
            "{action}", // URL with parameters
            new { controller = "Home", action = "Index" }, // Parameter defaults
            new { action = "TaskA|TaskB|TaskC|etc" } //Route constraints
        );

        routes.MapRoute(
            "Account", // Route name
            "{action}", // URL with parameters
            new { controller = "Account", action = "Logon" }, // Parameter defaults
            new { action = "Logon|Logoff|Profile|FAQs|etc" } //Route constraints
        );

这篇关于MVC 3保持短网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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