zoukankan      html  css  js  c++  java
  • .net core 3.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?}"
                            );
                });
  • 相关阅读:
    在线工具把C#代码转换成VB.NET代码
    document.execCommand()函数可用参数(整理收集)
    终于搞定sp_executesql的调用
    IIS 未被授权查看该页
    ajax学习笔记(1)
    Wscript.Shell 对象详细介绍!!特好的东西
    ASP.NET AJAX 客户端生命周期事件
    本人扩展的可绑定Dataset的Treeview,遇到不能展开的问题
    固定表头简单实现
    C#实现屏幕录像
  • 原文地址:https://www.cnblogs.com/taikongbai/p/13426423.html
Copyright © 2011-2022 走看看