c# - 删除和选项请求获得 401 未经授权的响应
问题描述
我正在使用托管在远程 IIS 服务器上的 .net core web api 3.1,每次删除/选项请求我都会收到 401 未经授权的html响应,我在启动时允许了 CORS,但没有运气。
更新:这是我的启动
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<BrmajaCommerceSearchContext>(options => options.UseSqlServer(Configuration.GetConnectionString("SearchConnectionString")));
services.AddDbContext<IdentityContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddCors(o => o.AddPolicy("AllowAll", b => b.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));
services.AddControllers().AddNewtonsoftJson(s =>
{
s.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Ecommerce API",
Version = "v1"
});
// Set the comments path for the Swagger JSON and UI.
var xmlFile = Assembly.GetExecutingAssembly().GetName().Name + ".xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
services.AddAuthentication()
}
// 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.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseCors("AllowAll");
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("swagger/v1/swagger.json", "Ecommerce");
c.RoutePrefix = string.Empty;
});
}
}
解决方案
描述行为的最可能原因是 IIS WebDAV 模块为这些 HTTP 动词提供服务。您必须使用 IIS 配置管理器或使用包含的 web.config 文件禁用它
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>
<configuration>
推荐阅读
- knn - 使用距离作为权重拟合 K-最近邻 mod w/n_neighbors
- jexcelapi - Using conditional formulas in JExcel
- hive - 将 hive-1.0 时间戳截断为秒,并将格式从“yyyy:mm:dd:ss.SSS”更改为“yyyy:mm:dd:ss”
- java - JDK 11.0.6_10 中的 SSLHandshake 错误,但在 Java8 中工作正常
- php - 表单验证codeigniter不起作用以及如何上传图片?
- html - Fontawesome 图标未显示
- wpf - 具有动态画笔属性的 DrawingBrush.GeometryDrawing
- image-processing - 按相对字体大小对图像上的文本进行排序
- javascript - JQuery点击触发器首先不起作用
- 标签
- c - 超过一定大小的二维矩阵不会在 C 中运行