首页 > Web开发 > 详细

.net core 3.0 路由及区域路由与默认首页的配置

时间:2020-08-03 19:03:48      阅读:222      评论:0      收藏:0      [点我收藏+]

Startup文件配置

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
        }
 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                        name: "areas",
                        pattern: "{area:exists}/{controller=Default}/{action=Index}/{id?}"
                        );
            });
        }

Controller页面

[Area("SqlFrame")]
public class DefaultController : Controller
{
public IActionResult Index()
{
return View();
}
}

 

默认页面配置方案1

在Properties下的launchSettings.json中

 "launchUrl": "SqlFrame",  设置访问的区域
{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:50114",
      "sslPort": 44345
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "SqlFrame",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "BaseCore": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }
}

或者是右键解决方案 属性 技术分享图片

 

2、默认页面 使用管道控制页面跳转

 app.UseEndpoints(endpoints =>
            {
                endpoints.Map("/",context =>
                {
                    context.Response.Redirect("/SqlFrame/Default/Index");
                    return Task.CompletedTask;
                });

                endpoints.MapControllerRoute(
                        name: "ss",
                        pattern: "{area:exists}/{controller}/{action}/{id?}"
                        );
            });

 

.net core 3.0 路由及区域路由与默认首页的配置

原文:https://www.cnblogs.com/taikongbai/p/13426423.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!