第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

app.UseMvcWithDefaultRoute();添加后會報(bào)錯(cuò)為啥呢

app.UseMvcWithDefaultRoute();添加后會提示System.InvalidOperationException:“Endpoint Routing does not support 'IApplicationBuilder.UseMvc(...)'. To use 'IApplicationBuilder.UseMvc' set 'MvcOptions.EnableEndpointRouting = false' inside 'ConfigureServices(...).”

正在回答

6 回答

是不是使用的是net core 3+?課程是基于2.2的,所以會跟3+有所不同。試試: "services.AddMvc(option => option.EnableEndpointRouting = false) .AddNewtonsoftJson();", 意思就是默認(rèn)禁用Endpoint Routing

2 回復(fù) 有任何疑惑可以回復(fù)我~

感覺像是依賴沒添加,截圖留下startup文件代碼,我可以仔細(xì)看看。

0 回復(fù) 有任何疑惑可以回復(fù)我~

要把

endpoints.MapGet("/", async context =>

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? await context.Response.WriteAsync("Hello World!");

? ? ? ? ? ? ? ? });

這句話刪掉,否則就會覆蓋HomeController里的設(shè)置

0 回復(fù) 有任何疑惑可以回復(fù)我~

?app.UseEndpoints(endpoints =>

? ? ? ? ? ? {

? ? ? ? ? ? ? ? endpoints.MapGet("/", async context =>

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? await context.Response.WriteAsync("Hello World!");

? ? ? ? ? ? ? ? });


? ? ? ? ? ? ? ? endpoints.MapDefaultControllerRoute();

? ? ? ? ? ? });

3.1版本,這么寫就OK啦,很簡單!

0 回復(fù) 有任何疑惑可以回復(fù)我~

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

? ? ? ? {

? ? ? ? ? ? if (env.IsDevelopment())

? ? ? ? ? ? {

? ? ? ? ? ? ? ? app.UseDeveloperExceptionPage();

? ? ? ? ? ? }


? ? ? ? ? ? app.UseRouting();


? ? ? ? ? ? app.UseEndpoints(endpoints =>

? ? ? ? ? ? {

? ? ? ? ? ? ? ? endpoints.MapGet("/", async context =>

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? await context.Response.WriteAsync("Hello World!");

? ? ? ? ? ? ? ? });


? ? ? ? ? ? ? ? endpoints.MapControllerRoute(

? ? ? ? ? ? ? ? ? ? name: "default",

? ? ? ? ? ? ? ? ? ? pattern: "{controller=Home}/{action=Index}/{id?}");

? ? ? ? ? ? });

? ? ? ? }

這是asp.net core 3.1的添加方法,用這個(gè)就行了

1 回復(fù) 有任何疑惑可以回復(fù)我~

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace CityGarden
{
??? public class Startup
??? {
??????? // This method gets called by the runtime. Use this method to add services to the container.
??????? // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
??????? public void ConfigureServices(IServiceCollection services)
??????? {
??????????? services.AddMvc();
??????? }

??????? // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
??????? //請求通道都是通過IApplicationBuilder創(chuàng)建的。
??????? //每個(gè)中間件都可以截獲、傳遞、修改請求對象,輸出響應(yīng)對象。
??????? //特定情況下某些中間件可以做短路處理,直接像前端輸出響應(yīng)對象。
??????? public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
??????? {
??????????? if (env.IsDevelopment())
??????????? {
??????????????? app.UseDeveloperExceptionPage();
??????????? }
??????????? //自定義路由

??????????? /*app.UseMvc(route =>
??????????? {
??????????????? route.MapRoute("default","{controller=Home}/{action=index}/{id?}");
??????????? });*/


??????????? app.Map("/test", build =>
??????????? {
??????????????? build.Run(async context =>
??????????????? {
??????????????????? await context.Response.WriteAsync("Hello form test!");
??????????????? });
??????????? });

??????? }
??? }
}


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

app.UseMvcWithDefaultRoute();添加后會報(bào)錯(cuò)為啥呢

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號