웹 API를 시작하는 데 문제가 있습니다. .net core 3.0 Web Api를 사용하고 있습니다. 나는 문제없이 iis express를 사용하여 로컬에서 디버깅하고 테스트했습니다. 하지만 웹 API를 내 Linux 서버에 배포하려고 할 때 다음과 같은 오류 메시지가 표시됩니다.
crit : Microsoft.AspNetCore.Server.Kestrel [0] Kestrel을 시작할 수 없습니다. System.InvalidOperationException : 경로 기준은 IApplicationBuilder.UsePathBase ()를 사용해서 만 구성 할 수 있습니다.
내 로컬 컴퓨터에서 디버그 모드로 실행하면 동일한 작업이 수행됩니다. 그래서 VS에서 응용 프로그램을 디버깅 할 때 실행 파일을 시작하는 새 프로필을 만들었습니다.
예외 발생 : System.Private.CoreLib.dll의 'System.InvalidOperationException'System.Private.CoreLib.dll에서 'System.InvalidOperationException'유형의 처리되지 않은 예외가 발생했습니다. 경로 기반은 IApplicationBuilder.UsePathBase ()를 사용해서 만 구성 할 수 있습니다.
다음은 Program.cs 및 Startup.cs의 코드입니다.
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureKestrel((a, b) => { })
.UseUrls("http://*:5050,https://*:5051")
.UseKestrel()
.UseStartup<Startup>();
}
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options => options.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
connectionObject.SetConfiguration(Configuration);
// configure strongly typed settings objects
var appSettingsSection = Configuration.GetSection("AppSettings");
services.Configure<AppSettings>(appSettingsSection);
// configure jwt authentication
var appSettings = appSettingsSection.Get<AppSettings>();
var key = Encoding.ASCII.GetBytes(appSettings.Secret);
services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(x =>
{
x.Events = new JwtBearerEvents
{
OnTokenValidated = context =>
{
var userService = context.HttpContext.RequestServices.GetRequiredService<IUserData>();
var userId = int.Parse(context.Principal.Identity.Name);
var user = userService.GetById(userId);
if (user == null)
{
// return unauthorized if user no longer exists
context.Fail("Unauthorized");
}
return Task.CompletedTask;
}
};
x.RequireHttpsMetadata = false;
x.SaveToken = true;
x.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = false,
ValidateAudience = false
};
});
// configure DI for application services
services.AddScoped<IUserData, UD>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseMvc();
}
}
여기 내 출시 설정이 있습니다
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:60850",
"sslPort": 44372
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "Executable",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Kestrel": {
"commandName": "Executable",
"executablePath": ".\\WebApi.exe",
"applicationUrl": "http://localhost:5050"
}
}
}
나는 만지작 거렸다
app.UsePathBase("/");
또는
app.UsePathBase("http://localhost:5050")
그러나 후자의 경우 오류 메시지는 값이 /로 시작해야한다는 것입니다.
나는 전에이 문제에 대해 다른 불평을 보았지만 그들의 해결책이 저에게 효과가 없었습니다. 나는 왜 이것을 얻습니까?
이 UseUrls(...)
메소드는 URL ;
이 쉼표가 아닌 세미콜론으로 구분 될 것으로 예상합니다 ,
.
줄을 다음 program.cs
으로 변경하십시오.
.UseUrls("http://*:5050;https://*:5051")
문서에 따르면 (강조 내) :
이러한 접근 방식을 사용하여 제공되는 값은 하나 이상의 HTTP 및 HTTPS 끝 점일 수 있습니다 (기본 인증서를 사용할 수있는 경우 HTTPS). 값을 세미콜론으로 구분 된 목록 으로 구성하십시오 (예 : "Urls": " http : // localhost : 8000; http : // localhost : 8001 ").
여기 에서 전체 문서를 볼 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다