C# Area区域配置,修改默认路由
2021-04-01 14:27
标签:移除 stat start ssi using erro apr mis routing 1.右键项目新建文件夹 Areas 2.先把项目分类包好,建两个文件夹,放Controller和View,Model也可以放在这里 因为项目启动默认打开的是Home/Index ,我把它放在了Website文件夹内了,这就需要更改路由配置了 3.如果更改了默认目录,就要去修改路由配置了,打开Global.asax.cs代码如下,F12进 RouteConfig 4.修改RouteConfig,主要修改就是加了 namespaces: new[] { "Demo.Web.Areas.Website.Controllers" } 和 route.DataTokens["area"] = "Website"; C# Area区域配置,修改默认路由 标签:移除 stat start ssi using erro apr mis routing 原文地址:https://www.cnblogs.com/layla/p/9235616.html
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace Demo.Web
{
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
// 移除X-AspnetMvc-Version HTTP 开头
MvcHandler.DisableMvcResponseHeader = true;
// 注册所有Area
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
AutofacConfig.Register();
PermissionUtil.ValidPermissions();
}
}
}
using System.Web.Mvc;
using System.Web.Routing;
namespace AnFund.Web
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
var route = routes.MapRoute("Default", "{controller}/{action}/{id}", new {controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Demo.Web.Areas.Website.Controllers" }
);
// 更改视图默认位置
route.DataTokens["area"] = "Website";
}
}
上一篇:C# 之泛型详解
文章标题:C# Area区域配置,修改默认路由
文章链接:http://soscw.com/index.php/essay/70969.html