Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.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
C# 如何解决HTTP错误404.15-找不到?_C#_Asp.net Mvc_Model View Controller_.net Core_Http Error - Fatal编程技术网

C# 如何解决HTTP错误404.15-找不到?

C# 如何解决HTTP错误404.15-找不到?,c#,asp.net-mvc,model-view-controller,.net-core,http-error,C#,Asp.net Mvc,Model View Controller,.net Core,Http Error,我在.NETCore2.2应用程序中工作。调用API时,我遇到HTTP错误404.15 因为我在URL中传递了大量项目 我没有权利更改IIS,如下所述 <configuration> <system.webServer> <security> <requestFiltering> <requestLimits maxQueryString="3000" maxUrl="1000" /> /* Change the Url limit h

我在.NETCore2.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>
在控制器中调用方法

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

    int i = bl.AddProduct<Product>(keyValues);
    return i;
}
public int InsertProduct(产品)
{
Dictionary keyValues=this.GetProperty(产品);
int i=bl.AddProduct(键值);
返回i;
}

因此,任何人都可以向我推荐一个更好的解决此问题的方法。解决此问题的最简单方法是使用POST。。。这样,查询字符串限制就不适用了

控制器中的操作应如下所示:

[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;
}
[HttpPost]//这是接受POST而不是GET
public int InsertProduct([FromBody]Product)
{
Dictionary keyValues=this.GetProperty(产品);
int i=bl.AddProduct(键值);
返回i;
}
还请注意,我在产品参数中添加了[FromBody]。 这样,控制器将期望json位于请求体内部,而不是url中,也不是表单集合中

您还需要将api调用更改为使用POST而不是GET。 因为您没有显示进行API调用的代码。。。。我不能帮你改成用POST

如果您发布了进行API调用的代码,我将更新此答案,向您展示如何使用post

最后注释: MaxRequestBodySize与您的问题无关,因此更改它毫无意义

限制设置用于查询字符串Url而不是请求的正文

只需查看配置文件中的这一行:

<requestLimits maxQueryString="3000" maxUrl="1000" /> /* Change the Url limit here */
/*在此处更改Url限制*/
您可以看到maxQueryStringmaxUrl这两个选项都会影响URL大小,而不是请求主体

身体是什么,是在一个职位的要求或放

事实上,我没有身体。。。如果他们这样做,服务器就会忽略它


因此,通过在帖子中发送数据,您将不会受到该限制的影响。

请向我们展示您如何尝试调用端点,以及您尝试调用的整个操作。我将编辑我的问题。您从何处调用该限制?就在地址栏里,还是从代码里?等等。。。。api调用显示的是GET请求而不是POST请求。。。。。然而你上传的文件使用的是POST。。。那你为什么不试着用POST来代替呢?此外,我还不清楚上传文件或InsertProduct调用中的错误在哪里。。。。请出示相关代码,我知道了。请看我的回答。我没有配置文件,只有app.settings.json文件。@ahamed你发布了一个xml文件。。。。appsettings是一个JSON文件。。。因此,您的配置有问题。你看这行不是JSON:/*在这里更改Url限制*/@ahamed我很确定你发布的XML来自配置文件。@ahamed顺便说一下,我的答案是正确的。解决这个问题的方法是按照我在书中所说的去做。我的版本是2.2。它不是一个XML文件。我提到appsettings的原因是,我没有配置文件。
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;
}
[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;
}
<requestLimits maxQueryString="3000" maxUrl="1000" /> /* Change the Url limit here */