Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Part of the benefit of ASP.NET MVC (and more generally, the URL Routing Engine common to all of ASP.NET in .NET 3.5 SP1) is that the URLs can be flexibly configured to map to any folder / file structure you prefer. That means it's much easier than it was in the days of WebForms to modify your URLs after you've started building your project.</p> <p>To your specific questions:</p> <ul> <li><p><strong>One Admin Controller vs. Product Controller</strong> - In general, the guidance is to keep controllers focused so that they are easier to test and maintain. For that reason, I would suggest using a single controller per object type (like Product) with your CRUD actions. Examples in your case:</p> <p>/admin/product/create</p> <p>/admin/product/edit/34 or /admin/product/edit/red-shoes (<em>if</em> name is unique)</p> <p>In either case, the Create, Edit, Deatils actions will all be in the ProductController. You may just have custom routes for the "admin actions" (like Create and Edit) that limit their usage (and add the "admin" text to the URL), and then the Details action would be usable by all visitors to your site.</p></li> <li><strong>Securing Admin Views</strong> - One important fact to remember with MVC: all requests go directly to controllers, not views. That means the old "secure a directory with web.config" does not apply (usually) to MVC for securing your Admin. Instead, you should now apply security directly to the controllers. This can easily be achieved by using attributes to Controller classes like: <ul> <li>[Authorize] - Just checks that the user is logged-in</li> <li>[Authorize(Roles = "Admin")] - Limit to specific user roles</li> <li>[Authorize(Users = "Joe")] - Limit to specific users</li> </ul></li> </ul> <p>You can even create a custom route for "Admin" views in your site and limit access to those views by enforcing your authorization check in the URL routing, like this:</p> <pre><code>routes.MapRoute( "Admin", "Admin/{controller}/{action}", new { controller = "Product", action = "Index" }, new { authenticated= new AuthenticatedConstraint()} ); </code></pre> <p>Where AuthenticatedConstraint looks something like:</p> <pre><code>using System.Web; using System.Web.Routing; public class AuthenticatedConstraint : IRouteConstraint { public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { return httpContext.Request.IsAuthenticated; } } </code></pre> <p>Good details on Stephen Walther's blog: <a href="http://stephenwalther.com/blog/archive/2008/08/07/asp-net-mvc-tip-30-create-custom-route-constraints.aspx" rel="noreferrer">ASP.NET MVC Tip #30 – Create Custom Route Constraints</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload