比如
domain.com/abcd/123在asp.net mvc中 abcd 是Controller  123是Action但是我现在的业务是abcd是未知的变量,存储在数据库中,用户根据登录后才真正找到应该指向到哪个链接。比如
A用户登录后到 domain.com/abcd/123B用户登录后到  domain.com/efgh/123C用户登录后台  domain.com/ijkl/123
或更多的用户,中间的abcd,efgh,ijkl 都是给用户自己定义的?请问怎么实现最好?

解决方案 »

  1.   

    业务逻辑有问题,Controller是写死的,程序中有几个Controller就是几个,不能再运行中动态生成
      

  2.   

    如果你非要这么写也不是不能实现,需要修改路由
                routes.MapRoute(
                    "Default", // 路由名称
                    "{id}/{action}/{controller}", // 带有参数的 URL
                    new { id = "abc", action = "Index", controller = "Test" } // 参数默认值
                );就是将controller,action,id换下位置将路径的第一段作为ID,第二段作为action。最后一段作为Controller例如:
    http://192.168.0.1/abcd/Index/Test
    http://192.168.0.1/1234/Index/Test后台对应:    public class TestController : Controller
        {
            public ActionResult Index(string id)
            {
                switch(id)
                {
                    case "abcd":
                         //你要做的事
                         break;
                    case "1234":
                         //你要做的事
                         break;
                    default:
                         //你要做的事
                }
                return View();
            }
        }