DevExpress ASPxUploadControl引发未指定的错误
本文关键字:错误 未指定 ASPxUploadControl DevExpress | 更新日期: 2023-09-27 18:29:15
如果在我的网站上有一个上传控制定义为:
<dx:ASPxUploadControl ID="ucStatement" runat="server" Width="200px"
ClientInstanceName="ucStatement" ClientVisible="true" AutoStartUpload="True"
OnFileUploadComplete="ucStatement_FileUploadComplete"
OnInit="ucStatement_Init"></dx:ASPxUploadControl>
ucStatement_FileUploadComplete
定义如下,当稍后使用ms
时:
MemoryStream ms;
protected void ucStatement_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
{
if (!e.UploadedFile.IsValid)
return;
ms = new MemoryStream();
e.UploadedFile.FileContent.CopyTo(ms);
}
在服务器上,它确实可以工作,但由于我们的安全技术人员更改了web配置以符合一些安全考虑,它抛出了错误:
服务器遇到内部未指定的错误,导致无法运行无法满足请求。
web配置的更改显然是这个功能不再工作的原因,但它们是非常小的更改,不应该影响这一点。
从DevExpress网站上的各种帖子中可以看出,他们说它可能被抛出以及如何缓解有很多原因https://www.devexpress.com/Support/Center/Question/Details/KA18611
解决那里提出的问题:
1.1当总请求长度超过"system.web>httpRuntime>maxRequestLength"web.config密钥允许的最大值时,通常会出现此问题
我只想上传一个约4kb的文件,我已经按照建议在网络配置中设置了:
<system.web>
<httpRuntime maxRequestLength="4096" />
...
</system.web>
和
<system.webServer>
...
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="30000000" />
</requestFiltering>
</security>
</system.webServer>
我也不会将UploadMode
更改为Advanced
,因为我不想强制执行Silverlight。
EDIT:进一步的调查显示,DXR.axd
中有一个名为GetFakeIframeDocument
的方法抛出了错误,我只能在DevEx工作人员说请求长度大于maxRequestLength
时找到该错误,但事实肯定不是这样。你能在这篇文章底部的web.config中看到任何否定此设置的内容吗?或者根本不允许上传?
1.2当web服务器返回意外响应/代码时,也可能出现这种情况。
他们建议将FileUploadMode
更改为OnPageLoad
。在这里这样做会产生同样的错误。
1.3"服务器遇到内部未指定错误,导致无法完成请求"错误也可能是由在Web.config文件中启用跟踪引起的。
web.config 中未设置跟踪
1.4是否可以自定义/覆盖"服务器遇到内部未指定错误,导致无法完成请求"错误消息?
他们建议通过捕获所有回调错误来捕获错误。我已经这样做了:
void Application_Start(object sender, EventArgs e) {
DevExpress.Web.ASPxWebControl.CallbackError += new EventHandler(Application_Error);
}
void Application_Error(object sender, EventArgs e)
{
HttpServerUtility server = HttpContext.Current.Server;
Exception ex = server.GetLastError();
if (ex is HttpUnhandledException)
ex = ex.InnerException;
ProcessException(ex)
}
ProcessException
执行许多不同的操作,写入事件日志、写入错误日志文件和插入SQL数据库。
若应用程序的任何其他部分抛出错误,所有这些函数都可以工作。当Upload控件抛出错误时,不会记录任何内容。
那么,可能是什么原因造成的呢?为什么这个错误没有击中Application_Error
函数?我该怎么办?
以下是完整披露的web.config:
<configuration>
<configSections>
<sectionGroup name="devExpress">
<section name="themes" type="DevExpress.Web.ThemesConfigurationSection, DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
<section name="compression" type="DevExpress.Web.CompressionConfigurationSection, DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
<section name="settings" type="DevExpress.Web.SettingsConfigurationSection, DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
<section name="errors" type="DevExpress.Web.ErrorsConfigurationSection, DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<add connectionString="xxxxx" name="myConnectionString" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<httpCookies httpOnlyCookies="true" requireSSL="true"/>
<compilation debug="false" targetFramework="4.5">
<assemblies>
<add assembly="DevExpress.Data.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.ASPxHtmlEditor.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.ASPxSpellChecker.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.ASPxTreeList.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.ASPxThemes.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.ASPxPivotGrid.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Utils.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Office.v14.2.Core, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.RichEdit.v14.2.Core, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.SpellChecker.v14.2.Core, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Charts.v14.2.Core, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.XtraCharts.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.XtraGauges.v14.2.Core, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.XtraGauges.v14.2.Presets, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.ASPxGauges.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.XtraCharts.v14.2.Web, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Printing.v14.2.Core, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.XtraReports.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.XtraReports.v14.2.Web, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.XtraPivotGrid.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.PivotGrid.v14.2.Core, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.XtraScheduler.v14.2.Core, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.ASPxScheduler.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Spreadsheet.v14.2.Core, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.ASPxSpreadsheet.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
</assemblies>
</compilation>
<authentication mode="Windows" />
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<sessionState timeout="5"></sessionState>
<httpHandlers>
<add type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" validate="false" />
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="DX.ashx" validate="false" />
</httpHandlers>
<httpModules>
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</httpModules>
<globalization culture="" uiCulture="" />
<httpRuntime maxRequestLength="4096" requestValidationMode="4.0" executionTimeout="110" />
<pages validateRequest="true" clientIDMode="AutoID">
<controls>
<add tagPrefix="dx" namespace="DevExpress.Web" assembly="DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
</controls>
</pages>
<authorization>
<allow users="*" />
</authorization>
<machineKey decryption="AES" validation="AES" />
<trust level="Full" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</modules>
<handlers>
<add type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" name="ASPxUploadProgressHandler" preCondition="integratedMode" />
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v14.2, Version=14.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="DX.ashx" name="ASPxHttpHandlerModule" preCondition="integratedMode" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="30000000" />
<fileExtensions allowUnlisted="true">
</fileExtensions>
</requestFiltering>
</security>
<httpErrors errorMode="Custom" />
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="DENY" />
<add name="X-Content-Type-Options" value="no sniff"/>
</customHeaders>
</httpProtocol>
</system.webServer>
<devExpress>
<themes enableThemesAssembly="true" styleSheetTheme="" theme="Metropolis" customThemeAssemblies="" />
<compression enableHtmlCompression="false" enableCallbackCompression="true" enableResourceCompression="true" enableResourceMerging="true" />
<settings doctypeMode="Html5" rightToLeft="false" embedRequiredClientLibraries="true" ieCompatibilityVersion="edge" />
<errors callbackErrorRedirectUrl=""/>
</devExpress>
</configuration>
当我意识到GetFakeIframeDocument
方法中出现错误后,我在web.config中搜索,以查找可能与iframe有关的任何内容。在httpProtocol
>customHeaders
中有一个元素:
<add name="X-Frame-Options" value="DENY" />
这将阻止任何iframe显示网站内容。将value
更改为SAMEORIGIN
允许网站使用iframe来显示网站内容,但禁止任何外部iframe显示网站内容。当我将上面的web.config元素更改为:时,一切都正常
<add name="X-Frame-Options" value="SAMEORIGIN" />