.NET System.Web.HttpContext.Current.Request报索引超出数组界限。

移动端使用Dio发送 FormData, 请求类型 multipart/form-data, FormData内可以一个或多个包含文件时。

请求接口时获取上传的fomdata数据使用 System.Web.HttpContext.Current.Request 接受时  报索引超出数组界限问题。

使用MultipartFormDataStreamProvider接受数据不受影响。

解决过程不多说。说多了都是泪。下面是解决方案

 

解决方法:

1.修改IIS的applicationhost.config

  a.文件位置: %windir%/system32/inetsrv/config/applicationhost.config

  b.找到 <requestFiltering> 节点

  c.然后找到<serverRuntime />此项。如果设置了uploadReadAheadSize的大小  则删除掉就可以了。

 

附加知识点:

iis7上传文件大小是有限制的。根据自己需求来进行设置相对应的处理

1.web.config中添加如下内容

<configuration>
<system.web>
      <httpRuntime maxRequestLength="上传大小的值(单位:byte)" executionTimeout="120"/>
 </system.web>
 </configuration>

2.web.config中,把以下内容加在<system.webServer>节点

<security>
 <requestFiltering >
    <requestLimits maxAllowedContentLength="上传大小的值(单位:KB)" >    
    </requestLimits>
 </requestFiltering>
</security>

 

 

在Java中,你可以通过使用`javax.servlet.ServletContext`接口来实现类似于C#中`System.Web.HttpContext.Current.Request.MapPath()`的功能。下面是一个示例代码: ```java import javax.servlet.ServletContext; public class MapPathExample { public static String mapPath(String path) { ServletContext context = ServletContextProvider.getServletContext(); // 通过Provider获取ServletContext对象 String realPath = context.getRealPath(path); // 获取真实路径 return realPath; } } class ServletContextProvider { private static ServletContext servletContext; public static void setServletContext(ServletContext context) { servletContext = context; } public static ServletContext getServletContext() { return servletContext; } } ``` 在你的Java Web应用程序的`web.xml`文件中,你需要添加一个`ServletContextListener`来设置`ServletContext`对象。下面是一个示例`web.xml`文件的配置: ```xml <web-app> <!-- 其他配置 --> <listener> <listener-class>com.example.ServletContextListenerImpl</listener-class> </listener> </web-app> ``` 然后,你需要实现`ServletContextListener`接口,在`contextInitialized`方法中设置`ServletContext`对象。下面是一个示例`ServletContextListener`的实现: ```java import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class ServletContextListenerImpl implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext context = servletContextEvent.getServletContext(); ServletContextProvider.setServletContext(context); } @Override public void contextDestroyed(ServletContextEvent servletContextEvent) { // 需要实现该方法,可以留空 } } ``` 现在,你可以在你的Java代码中使用`MapPathExample.mapPath(path)`方法来获取路径的真实物理路径,就像在C#中使用`System.Web.HttpContext.Current.Request.MapPath()`一样。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值