如何解决HTTP错误404.15-未找到?

问题描述 投票:0回答:1

我正在.NET Core 2.2应用程序中工作。调用API时收到HTTP错误404.15。

由于我在URL中传递的项目数量很大。

而且我没有如下所述更改IIS的特权。

<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxQueryString="3000" maxUrl="1000" /> /* Change the Url limit here */
</requestFiltering>
</security>
</system.webServer>
</configuration>

我也尝试了以下解决方案,但不起作用。

[HttpPost]
[RequestSizeLimit(40000000)]
public async Task<IActionResult> UploadFiles(IFormFile file)
{

}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()
    .UseKestrel(options =>
    {
        options.Limits.MaxRequestBodySize = 52428800; //50MB
    });
}
app.UseWhen(context => context.Request.Path.StartsWithSegments("/api"), appBuilder =>
{
    context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = null;
    //TODO: take next steps
});

这是我的API调用

https://localhost:44473/ControllerName/InsertProduct?ProductSubCategoryId="4"&ProductName="Canon EOS 200D II DSLR Camera EF-S 18 - 55 mm IS STM and 55 - 250 mm IS STM  (Black)"&ProductDescription="Is photography one of your passions? Bring home this EOS 200D II from Canon. This is Canon’s lightest DSLR that features a vari-angle LCD touch screen. It features a 24.1-megapixels APS-C CMOS sensor and a DIGIC 8 processor that capture stunning images. The EOS 200D II also has a lot of other features that make everyday photography a lot easier."&ProductSpecification="{"Specification":[{"In The Box": "1 Camera Body, 18 - 55 mm Lens, 55 - 250 mm Lens, Battery, Battery Charger, USB Cable, Camera Bag"},{"Model Number": "EOS 200D II"},{"Model Name": "eos200dii"},{"SLR Variant": "EF-S 18 - 55 mm IS STM and 55 - 250 mm IS STM"},{"Effective Pixels": "24.1 MP"},{"Image Sensor Size": "22.3 x 14.9"},{"Sensor Type": "CMOS"},{"Lens Mount": "EF Mount"},{"Shutter Speed": "1/4000 - 30 sec"},{"Image Format": "JPEG, RAW, C-RAW, RAW + JPEG, C-RAW + JPEG"},{"Video Resolution": "1920 x 1080"},{"Video Quality": "Full HD"},{"Battery Type": "Lithium"},{"Weight": "654g"}]}"&ProductOptions="{"Options":[{"Bank Offer":"10% Instant discount with HDFC Bank PayZapp Card on purchase of Rs.300 or more"},{"No Cost EMI": "Avail No Cost EMI on select cards for orders above ?3000"},{"Partner Offers":"Get FLAT 5% BACK with Amazon Pay ICICI Bank Credit card card for Prime members. Flat 3% BACK for non-Prime members. No minimum order value. No upper limit on cashback."}]}"&ProductPrice="57499"&ProductBrand="Canon"&IsActive="True"&Quantity="50"&ImageURL="NULL"

控制器中的调用方法

public int InsertProduct(Product product)
{
    Dictionary<string, object> keyValues = this.GetProperty<Product>(product);

    int i = bl.AddProduct<Product>(keyValues);
    return i;
}

所以任何人都可以建议我一个更好的主意来解决此问题。

c# asp.net-mvc model-view-controller .net-core http-error
1个回答
0
投票

解决此问题的最简单方法是使用POST调用InsertProduct ...这样,查询字符串限制将不适用。

喜欢这个:

[HttpPost]
public int InsertProduct([FromBody]Product product)

此外,您将需要更改api调用以使用POST而不是GET。

© www.soinside.com 2019 - 2024. All rights reserved.