Asp.net core Clean.net 5 api项目始终在iis中重定向到https
我有一个干净的.NET5API项目,在访问网站ThewIIS10时,出于某种原因,它总是重定向(307)到https。网站创建时未启用https。设置的唯一特殊之处是iis中的站点使用在主机文件中定义的自定义域(api.projectname.dev),该域指向127.0.0.1。如果我使用visualstudio使用iisexpress运行api,它不会重定向。默认的iis站点不会重定向到https。有人知道这可能是什么原因吗 Program.csAsp.net core Clean.net 5 api项目始终在iis中重定向到https,asp.net-core,iis,iis-10,Asp.net Core,Iis,Iis 10,我有一个干净的.NET5API项目,在访问网站ThewIIS10时,出于某种原因,它总是重定向(307)到https。网站创建时未启用https。设置的唯一特殊之处是iis中的站点使用在主机文件中定义的自定义域(api.projectname.dev),该域指向127.0.0.1。如果我使用visualstudio使用iisexpress运行api,它不会重定向。默认的iis站点不会重定向到https。有人知道这可能是什么原因吗 Program.cs public class Program {
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.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.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "project.Api", Version = "v1" });
});
}
// 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();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "project.Api v1"));
}
app.UseRouting();
//app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="bin\Debug\net5.0\project.Api.exe" arguments="" stdoutLogEnabled="false" hostingModel="InProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
从程序或启动中删除UseHttpsRedirection()行。cs项目不包含UseHttpsRedirect(),请让我们查看您的应用程序设置,属性和启动文件。它应该是UseHttpsRedirection
。正如您所知,答案中UseHttpsRedirection的口述并不重要:|因为如果它确实存在于他的代码中,他可以找到它@LexLiBut显然不是因为你的打字错误。你的启动是否包含app.UseHsts()代码>?在谷歌上搜索“http-force-to-https”@Magnetron它不包含app.UseHsts();首先跟踪发送307响应的人,将日志设置为调试,并查看何时发生重定向。