ASP.NET MVC How many levels deep should a view or URL be?

前端 未结 3 1810
轻奢々
轻奢々 2021-02-09 09:46

I am still learning ASP.NET MVC. With webforms, I would create a new folder let\'s call it admin. In there I might have many pages for create_product, edit_product, etc. So t

3条回答
  •  时光取名叫无心
    2021-02-09 10:29

    I3Dx definitely has the right guidance for the Authorize attribute, this is essential for keeping controller secure, you can apply to a controller or individual actions.

    As far as the URL depth, I would not worry about the depth, I would be more concerned that the route made logical sense for example:

    domain.com/admin/products/edit/1

    domain.com/admin/groups/edit/1

    domain.com/products/view/1

    domain.com/groups/view/1

    This way you know what is happening with each route. it is obvious that one is an admin and one is an end user.

    The easyest way to check is to get someone to read your URL and ask them what they would expect to see.

    Hope this helps.

    OH and one last thing, for client side routes we often use "slugs" rather than ids so that it is more readable. So when someone creates a product we slugify the name so it can be used in the route such as:

    domain.com/products/view/big-red-bucket

    rather than

    domain.com/products/view/1

提交回复
热议问题