简体   繁体   English

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

[英]How to resolve HTTP Error 404.15 - Not Found?

I am working in .NET core 2.2 application.我在 .NET core 2.2 应用程序中工作。 While calling API I got HTTP Error 404.15.在调用 API 时,我收到 HTTP 错误 404.15。

Since I am passing large no of Items in URL.因为我在 URL 中传递了大量的项目。

And I don't have privilege to change IIS as stated below.而且我无权更改 IIS,如下所述。

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

I also tried the following solutions, but its not working.我也尝试了以下解决方案,但它不起作用。

[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
});

This is my API call这是我的 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"

Calling Method in Controller控制器中的调用方法

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

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

So Anyone can suggest me a better Idea to resolve this issue.所以任何人都可以建议我一个更好的想法来解决这个问题。

The easiest way to fix this is to call InsertProduct using POST... That way the query string limit does NOT apply.解决此问题的最简单方法是使用 POST 调用 InsertProduct... 这样查询字符串限制不适用。

Your action in your controller should look Like this:您在控制器中的操作应如下所示:

[HttpPost]//this is to accept a POST rather than a GET
public int InsertProduct([FromBody]Product product)
{
    Dictionary<string, object> keyValues = this.GetProperty<Product>(product);

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

Notice also that I added [FromBody] to the Product parameter.另请注意,我将[FromBody]添加到 Product 参数。 That way the controller will expect the json to be inside the body of the request and NOT in the url, nor from the form collection.这样,控制器将期望 json 位于请求正文中,而不是在 url 中,也不在表单集合中。

Also you will need to change the api call to use POST and not GET.此外,您还需要更改 api 调用以使用 POST 而不是 GET。 Because you did NOT show the code that makes the API call.... I cannot help you change that to use POST..因为您没有显示进行 API 调用的代码......我无法帮助您将其更改为使用 POST..

If you post the code that makes the API call I will update this answer to show you how to use POST.如果您发布进行 API 调用的代码,我将更新此答案以向您展示如何使用 POST。

Final Notes: MaxRequestBodySize had NOTHING to do with your problem so changing it is meaningless...最后说明: MaxRequestBodySize 与您的问题无关,因此更改它毫无意义......

The limit set is for the Query String and the Url NOT the Body of the request...限制集的查询字符串URL不是请求的实体...

Just look at this line in your config file:只需查看配置文件中的这一行:

<requestLimits maxQueryString="3000" maxUrl="1000" /> /* Change the Url limit here */

You see maxQueryString and maxUrl both of those affect the URL size NOT the body of the request.您会看到maxQueryStringmaxUrl都影响 URL 大小而不是请求的正文。

Body is what is inside the request during a POST or PUT...正文是在 POST 或 PUT 期间请求内部的内容...

As a matter of fact GET request have NO body... and if they do the server IGNORES it.事实上,GET 请求没有正文......如果他们这样做,服务器会忽略它。

So by sending the data in a POST you will not be affected by that limit.因此,通过在 POST 中发送数据,您将不受该限制的影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM