Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core .netcore web API Post在没有SSL的情况下无法工作_Asp.net Core_Model View Controller_Ssl Certificate - Fatal编程技术网

Asp.net core .netcore web API Post在没有SSL的情况下无法工作

Asp.net core .netcore web API Post在没有SSL的情况下无法工作,asp.net-core,model-view-controller,ssl-certificate,Asp.net Core,Model View Controller,Ssl Certificate,我有一个带有控制器、API控制器和一些视图的MVC core 2.2应用程序。某些视图使用同一应用程序中的API端点。在我在windows服务器中启用TLS 1.2之前,一切正常。 现在,所有装饰为GET方法的端点都工作了。但所有帖子都已停止使用chrome报告此POST'link'net::ERR\u CONNECTION\u RESET。 其他浏览器在失败时捕获异常,并使用对象显示我的错误文本 $.ajax({ url:“/api/Cart”, 方法:“张贴”, 数据:JSON.string

我有一个带有控制器、API控制器和一些视图的MVC core 2.2应用程序。某些视图使用同一应用程序中的API端点。在我在windows服务器中启用TLS 1.2之前,一切正常。 现在,所有装饰为GET方法的端点都工作了。但所有帖子都已停止使用chrome报告此
POST'link'net::ERR\u CONNECTION\u RESET
。 其他浏览器在失败时捕获异常,并使用对象显示我的错误文本

$.ajax({
url:“/api/Cart”,
方法:“张贴”,
数据:JSON.stringify(vm),
contentType:“应用程序/json”
}).完成(功能(结果){
控制台日志(结果);
}).失败(功能(ex){
console.log(“添加到购物车时出错”+ex)
});
我想能够张贴即使没有SSL。我已禁用TLS 1.2并重新启动,但结果仍然相同。 如果我使用https://浏览站点,POST和GET端点都能正常工作,但是如果我使用HTTP://浏览站点,只使用GET端点工作,则所有POST端点都不能工作。 我花了将近5个小时在网上搜寻一些我认为很简单的东西

public void ConfigureServices(IServiceCollection services)
    {
        var connectionString = Configuration.GetConnectionString("DataConnection");
        services.AddDbContext<DataContext>(options => options.UseSqlServer(connectionString));

        //Inject Connection String to other Classes
        services.AddSingleton(_ => connectionString);

        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<DataContext>()
            .AddDefaultTokenProviders();

        services.ConfigureApplicationCookie(options =>
        {
            options.Cookie.HttpOnly = true;
            options.ExpireTimeSpan = TimeSpan.FromHours(1);
        });
        services.AddScoped<IUnitOfWork, UnitOfWork>();


        services.AddMediatR(typeof(CreateProductCommand).Assembly, typeof(CreateProductCommandHandler).Assembly);
        services.AddAutoMapper(typeof(MappingProfile));

        // Add memory cache services
        services.AddMemoryCache();

        services.AddMvc(o =>
        {
            var policy = new AuthorizationPolicyBuilder()
                .RequireAuthenticatedUser()
                .Build();
            o.Filters.Add(new AuthorizeFilter(policy));
        })  .SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);
    }

    // HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();

        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }
        var serviceProvider = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope().ServiceProvider;
        DataContextSeed.Initialize(serviceProvider);

        app.UseStaticFiles();
        app.UseAuthentication();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
public void配置服务(IServiceCollection服务)
{
var connectionString=Configuration.GetConnectionString(“数据连接”);
services.AddDbContext(options=>options.UseSqlServer(connectionString));
//向其他类注入连接字符串
services.AddSingleton(=>connectionString);
服务.额外性()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
services.configureApplicationOK(选项=>
{
options.Cookie.HttpOnly=true;
options.ExpireTimeSpan=TimeSpan.FromHours(1);
});
services.addScope();
AddMediatR(typeof(CreateProductCommand).Assembly,typeof(CreateProductCommandHandler).Assembly);
AddAutoMapper(类型(映射配置文件));
//添加内存缓存服务
services.AddMemoryCache();
services.AddMvc(o=>
{
var policy=new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()文件
.Build();
o、 过滤器。添加(新的过滤器(策略));
}).SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);
}
//HTTP请求管道。
公共无效配置(IApplicationBuilder应用程序,IHostingEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
其他的
{
app.UseExceptionHandler(“/Home/Error”);
}
var serviceProvider=app.ApplicationServices.GetRequiredService().CreateScope().serviceProvider;
初始化(serviceProvider);
app.UseStaticFiles();
app.UseAuthentication();
app.UseMvc(路由=>
{
routes.MapRoute(
名称:“默认”,
模板:“{controller=Home}/{action=Index}/{id?}”);
});
}
上面是Startup类,这里有一个示例帖子

[HttpPost]
    public IActionResult Post([FromBody] SaleItemDTO md)
    {
        if(md != null)
        {
            if(md.Quantity <= md.Stock)
            {
                _sales.SalesPerson = User.Identity.Name;
                _sales.SalesType = md.SalesType;
                return Ok(_sales.ItemsInDb);
            }
        }
        return BadRequest(new { Message = "Not Valid Content posted" });
    }
[HttpPost]
公共IActionResult Post([FromBody]SaleItemDTO md)
{
如果(md!=null)
{

如果(md.Quantity这是一个配置问题,而不是JS/jQuery问题。你能用一个示例post方法发布你的启动类和api控制器吗?因为听起来你正在通过HTTPS运行api,这将阻止来自HTTPS的post请求共享启动类,显示你正在添加到管道中的过滤器…已经添加了启动类和sample柱端点