在hottowel asp.net mvc4中基于用户的路由和子路由 [英] Route and subroute based on user in hottowel asp.net mvc4

查看:88
本文介绍了在hottowel asp.net mvc4中基于用户的路由和子路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:已更新

谁能帮助我找到如何根据用户创建路由和子路由的方法 是否可以创建 小部件 如果可以的话会完成工作

can anyone help me found out how to create routes and subroute based on user is it possible to create a Widget that will do the job if so how

这是我的菜单的外观(注意:所有菜单项一起称为 master ):

this is how my menu looks like (note:all menu items together let us call it master):

-Home
-shop
    -men
    -women
-food
    -dog
    -human
-cart
-settings
    -user
    -images
    -themes

假设我具有以下userGroup:

let say i have the following userGroup:

-Admin
-visitors
-vip
-costumers
-co-workers

我想做些什么

if(user == Admin){
   destroy the current menu then make a copy of master **master** remove subroute women and subroute dog then push 
}else if(user == visitor){
   ...
}

或者有更好的方法可以做到这一点,我可以在哪里定义它?

or is there a better way to do this and where i am supose to define it?

推荐答案

首先,您可能要考虑将项目升级到Durandal 2.0,因为它消除了对sammy.js的依赖,转而使用了更好的自定义路由器(Durandal 1.0现在已经过时了).这是有关升级的页面: http://durandaljs.com/documentation/Conversion-Guide/

First you might want to consider upgrading your project to Durandal 2.0 since it removes the dependency on sammy.js in favor of a custom router which works much better (Durandal 1.0 is essentially obsolete now). Here is the page on upgrading: http://durandaljs.com/documentation/Conversion-Guide/

,这是新路由器上的文档: http://durandaljs.com/documentation/使用路由器/

and here are the docs on the new router: http://durandaljs.com/documentation/Using-The-Router/

关于处理基于用户的路由,因为router.map只需要一个路由数组,所以您可以有条件地构建该数组并将其传递给router.map

As for handling the routing based on user, since router.map just expects an array of routes you can just build up the array conditionally and pass it to router.map

var routes = [ { route: '', moduleId: 'hello/index', title: 'Hello World', nav: true },
            { route: 'men', moduleId: 'men/index', title: 'Men',  nav: true }]
if(user == Admin){
    routes.push({ route: 'admin', moduleId: 'admin/index', title: 'Admin',  nav: true }
}else if(user == visitor){
    routes.push({ route: 'women', moduleId: 'women/index', title: 'women',  nav: true }
}
return router.map(routes)
          .buildNavigationModel()
          .mapUnknownRoutes('hello/index', 'not-found')
          .activate();

这篇关于在hottowel asp.net mvc4中基于用户的路由和子路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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