Web.config 常见配置(IIS)

本文详细记录了IIS中关于MVC的常见配置,包括增加FileExtension(mime map)和设置maxAllowedContentLength,以及如何处理HTTP异常,如HttpException和InvalidOperationException。针对无法正常处理的URL编码表单数据、文件上传和JSON负载问题,提供了具体的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

记录常见MVC 配置项,后续会不断更新。

1. IIS增加FileExtendsion(mime map) 和 maxAllowedContentLength

在 system.webServer 节点中增加 staticContent,

  <system.webServer>
    <staticContent>
      <remove fileExtension=".woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
      <remove fileExtension=".wasm" />
      <remove fileExtension=".mem" />
      <remove fileExtension=".json" />
      <remove fileExtension=".appcache" />
      <mimeMap fileExtension=".wasm" mimeType="application/javascript" />
      <mimeMap fileExtension=".mem" mimeType="application/javascript" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <mimeMap fileExtension=".appcache" mimeType="application/javascript" />

    </staticContent>
    <!--Add maxAllowedContentLength-->
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="102400000" />
      </requestFiltering>
    </security>

  </system.webServer>

 

 

2. https://support.microsoft.com/en-us/help/2661403/an-asp-net-request-that-has-lots-of-form-keys-files-or-json-payload-me

1.1 Message 1:

Application information: 
Application domain: /LM/W3SVC/1/ROOT/<App Domain>
Trust level: Medium 
Application Virtual Path: <VDIR Path>
Application Path: <App Path>
Machine name: <Machine Name>
Process information: 
Process ID: 0001 
Process name: w3wp.exe 
Account name: IIS APPPOOL\DefaultAppPool 

Exception information: 
Exception type: HttpException 
Exception message: The URL-encoded form data is not valid. 
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.get_Form()
at System.Web.HttpRequest.get_HasForm()
at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
at System.Web.UI.Page.DeterminePostBackMode()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 

 

1.2 Message 2:

Application information: 
Application domain: /LM/W3SVC/1/ROOT/<App Domain> 
Trust level: Medium 
Application Virtual Path: <VDIR Path> 
Application Path: <App Path> 
Machine name: <Machine Name>

Process information: 
Process ID: 0001
Process name: w3wp.exe 
Account name: IIS APPPOOL\DefaultAppPool 

Exception information: 
Exception type: InvalidOperationException 
Exception message: Operation is not valid due to the current state of the object. 
at System.Web.HttpRequest.FillInFilesCollection()
at System.Web.HttpRequest.get_Files()
at FileUpload.Page_Load(Object sender, EventArgs e) 
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint

 

1.3 Message 3:

Application information:
Application domain: /LM/W3SVC/1/ROOT/<App Domain> 
Trust level: Medium 
Application Virtual Path: <VDIR Path> 
Application Path: <App Path>
Machine name: <Machine Name>

Process information: 
Process ID: 0001
Process name: w3wp.exe 
Account name: IIS APPPOOL\DefaultAppPool 

Exception information: 
Exception type: InvalidOperationException 
Exception message: Operation is not valid due to the current state of the object. 
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)
at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
at System.Web.Script.Serialization.JavaScriptSerializer.DeserializeObject(String input)
at Failing.Page_Load(Object sender, EventArgs e) 
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Resolution:解决方案

  • Message 1 and Message 2
<configuration>
<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="1000" />
</appSettings>
</configuration>
  • Message 3
<configuration>
<appSettings>
<add key="aspnet:MaxJsonDeserializerMembers" value="1000" />
</appSettings>
</configuration>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值