.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?}"
                        );
            });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM