如何在ASP.NET MVC中未指定其区域的情况下阻止请求操作

时间:2014-01-20 07:00:52

标签: c# asp.net-mvc asp.net-mvc-routing url-routing asp.net-mvc-areas

我在root中有一些控制器,我已将这样的路由注册为默认值:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

我有一个名为'Admin'的区域,其溃败注册如下:

public class AdminAreaRegistration : AreaRegistration 
{
    public override string AreaName 
    {
        get 
        {
            return "Admin";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            "Default_Admin",
            "Admin/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
    }
}

我的问题是用户可以在管理区域内的控制器内请求操作(例如:UserController / Index),而不在URL中指定其区域。

我的意思是这两个网址都是一样的:

http://localhost:2374/Admin/Default1/Index
http://localhost:2374/Default1/Index

我想避开第二个网址。

由于

0 个答案:

没有答案