简体   繁体   中英

Base64 string is too long

I have made webservice to receive base64string and image name from android app . but the problem is when i pass a value of base64string into webservice i get an error

</style> 

</head> 
<body> 
<div id="content"> 
<div class="content-container"> 
  <h3>HTTP Error 404.15 - Not Found</h3> 
  <h4>The request filtering module is configured to deny a request where the query string is too long.</h4> 
</div> 
<div class="content-container"> 
 <fieldset><h4>Most likely causes:</h4> 
  <ul>  <li>Request filtering is configured on the Web server to deny the request because the query string is too long.</li> </ul> 
 </fieldset> 
</div> 
<div class="content-container"> 
 <fieldset><h4>Things you can try:</h4> 
  <ul>  <li>Verify the configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString setting in the applicationhost.config or web.config file.</li> </ul> 
 </fieldset> 
</div> 

<div class="content-container"> 
 <fieldset><h4>Detailed Error Information:</h4> 
  <div id="details-left"> 
   <table border="0" cellpadding="0" cellspacing="0"> 
    <tr class="alt"><th>Module</th><td>&nbsp;&nbsp;&nbsp;RequestFilteringModule</td></tr> 
    <tr><th>Notification</th><td>&nbsp;&nbsp;&nbsp;BeginRequest</td></tr> 
    <tr class="alt"><th>Handler</th><td>&nbsp;&nbsp;&nbsp;ExtensionlessUrlHandler-Integrated-4.0</td></tr> 
    <tr><th>Error Code</th><td>&nbsp;&nbsp;&nbsp;0x00000000</td></tr> 

   </table> 
  </div> 
  <div id="details-right"> 
   <table border="0" cellpadding="0" cellspacing="0"> 
    <tr class="alt"><th>Requested URL</th><td>&nbsp;&nbsp;&nbsp;http://localhost:36690/api/Data/GetImage?base64String=iVBORw0KGgoAAAANSUhEUgAAAQsAAAELCAYAAADOVaNSAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAF39JREFUeNrsnW1y2sj2xhUq3/FdAdwVwF0BygrsWzVT89FkBSYrCFlB8AqMP07NVI29gogd4BUM7MCsIH9OcnSHf7uFXmhJrdbvV0U5ARtQ99Gj55x+0bvv379HAAB5DGgCAEAsAACxAAD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PkX70ab1Ej9yFnOj3Ff/cq6nrNbuLSZVUpIpYhJ6CpIGXTpEuKxjPrpYEQ6V+W1RwhT5OXXfJk4tUpJRY9CEFMQJPag4y5+K5YMB90QlP0G6/iVh/iopNbfdyRqqPqUipzW90MYq589K/A1bk02OfagPHhmBuVLmffG0HHequa6LZzvPjnutV9HQHKTlxRBzWfblBt+7LYm638K8y67jKioW565KkINMIfAuMsZ4gNyoSTcxK9F40iYkfmzid8rHMRMqyNYvrArkQtBcQsQr633oVmUXNTV+e6Wf+ffwOiS7sAr9TkVJ99L5MIFqeRiz8sdvrqP69NssIxzfdQHaO0/CGxEihS9XXyjgL840PTDryQiikX3YeCYUpGtsQdqAKBPPiPiyzbL2MWMS4Cu+EQk7CvyK/V0rKd3s4flcWqrWfiiQFzuvLxEJt7sRiaaBdoXjo0Fe+C2hT3C7znJMxXOws4oz8BxCKMtySkrSOed46T0PMN9xTtGpNKMZRt1f4Pnh4b5U+YdYZC9ctio6GxH</td></tr> 
    <tr><th>Physical Path</th><td>&nbsp;&nbsp;&nbsp;E:\WebService\WebService\api\Data\GetImage</td></tr> 
    <tr class="alt"><th>Logon Method</th><td>&nbsp;&nbsp;&nbsp;Not yet determined</td></tr> 
    <tr><th>Logon User</th><td>&nbsp;&nbsp;&nbsp;Not yet determined</td></tr> 
    <tr class="alt"><th>Request Tracing Directory</th><td>&nbsp;&nbsp;&nbsp;C:\Users\abdelrahman.Mohamed\Documents\IISExpress\TraceLogFiles\WEBSERVICE</td></tr> 
   </table> 
   <div class="clear"></div> 
  </div> 
 </fieldset> 
</div> 

<div class="content-container"> 
 <fieldset><h4>More Information:</h4> 
  This is a security feature. Do not change this feature unless the scope of the change is fully understood. You can configure the IIS server to reject requests whose query string is greater than a specified value. If the request's query string is greater than the configured value, this error is returned. If the allowed length of the query string needs to be increased, modify the configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString setting. 
  <p><a href="http://go.microsoft.com/fwlink/?LinkID=62293&amp;IIS70Error=404,15,0x00000000,10240">View more information &raquo;</a></p> 

 </fieldset> 
</div> 
</div> 
</body> 
</html> 

And here is my webservice :

[HttpPost]
        [ActionName("GetImage")]
        public string GetImage(string base64String, string imgName)
        {
            try
            {
            byte[] imageBytes = Convert.FromBase64String(base64String);
                MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);


                ms.Write(imageBytes, 0, imageBytes.Length);
                System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);

                File.WriteAllBytes(Path.Combine
                (@"F:\FileManager\"
                , imgName
                )
              , imageBytes
              );

                return "Success";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

I don't know if i need to do some thing in my web.config or minimize the length of base64string . Any Ideas .Thanks

Yes you need to do changes in the web.config. When you look at the provided error it says

This is a security feature. Do not change this feature unless the scope of the change is fully understood. You can configure the IIS server to reject requests whose query string is greater than a specified value. If the request's query string is greater than the configured value, this error is returned. If the allowed length of the query string needs to be increased, modify the configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString setting.

Add the following to your web.config

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxQueryString="32768"/>
    </requestFiltering>
  </security>
</system.webServer>

and

<httpRuntime maxQueryStringLength="32768" maxUrlLength="65536"/>

as described in the following references requestLimits Element for requestFiltering [IIS Settings Schema] , Request Filtering and httpRuntime Element (ASP.NET Settings Schema) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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