anothershrubery
anothershrubery

Reputation: 21023

DevExpress ASPxUploadControl throwing unspecified error

If have an upload control on my site defined as:

<dx:ASPxUploadControl ID="ucStatement" runat="server" Width="200px" 
ClientInstanceName="ucStatement" ClientVisible="true" AutoStartUpload="True" 
OnFileUploadComplete="ucStatement_FileUploadComplete" 
OnInit="ucStatement_Init"></dx:ASPxUploadControl>

ucStatement_FileUploadComplete is defined as below, when ms is used later:

MemoryStream ms;

protected void ucStatement_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
{
    if (!e.UploadedFile.IsValid)
        return;

    ms = new MemoryStream();

    e.UploadedFile.FileContent.CopyTo(ms);
}

On the server it DID work, but since our security technician changed the web config to comply with some security considerations, it throws the error:

The server encountered an internal unspecified error that prevented it from fulfilling the request.

The web config changes are obviously high up on the list as to why this function isn't working anymore, but they are very minor changes that shouldn't impact this.

Looking in to this from various postings on the DevExpress site there are a number of reasons why they say it could be thrown and how to mitigate it. The most relevant post being https://www.devexpress.com/Support/Center/Question/Details/KA18611

Addressing the issues raised there:

1.1 This issue usually occurs when the total request length exceeds the maximum allowed via the "system.web > httpRuntime > maxRequestLength" Web.config key

I am only trying to upload a ~4kb file and I have set in the web config as advised:

<system.web>
    <httpRuntime maxRequestLength="4096" />
    ...
</system.web>

And

<system.webServer>
    ...
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="30000000" />
        </requestFiltering>
    </security>
</system.webServer>

I also won't change the UploadMode to Advanced as I don't want to enforce Silverlight.


EDIT: Further investigation shows a method in DXR.axd called GetFakeIframeDocument throwing the error which I can only find referenced by DevEx staff when they say the request length is greater than maxRequestLength but this is certainly not the case. Is there anything you can see in the web.config at the bottom of this post that would negate this setting? Or not allow any uploads at all?


1.2 This situation can also occur when a web server returns unexpected response/code.

They advise to change FileUploadMode to OnPageLoad. Doing so here gives the same error.

1.3 The "The server encountered an internal unspecified error that prevented it from fulfilling the request" error can also be caused by enabling tracing in the Web.config file.

Tracing is not set up in the web.config

1.4 Is it possible to customize/override the "The server encountered an internal unspecified error that prevented it from fulfilling the request" error message?

They advise capturing the error by capturing all CallBack errors. I already do this as such:

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 does a number of different things, writes to the event log, writes to an error log file and inserts into a SQL database.

All of the these functions work if an error is thrown by any other part of the application. When the Upload Control throws the error, nothing is logged.

So, what could possibly be causing this? Why might this error not hit the Application_Error function? What should I do?

Below is the web.config for full disclosure:

<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>

Upvotes: 2

Views: 3900

Answers (1)

anothershrubery
anothershrubery

Reputation: 21023

After I realised the error was thrown in the GetFakeIframeDocument method I searched through the web.config to find anything that might relate to iframes. In httpProtocol > customHeaders there is the element:

 <add name="X-Frame-Options" value="DENY" />

This stops ANY iframes from displaying the site content. Changing value to SAMEORIGIN allows the site to use iframes to display site content, but disallows any external iframes from displaying the site content. Everything works when I change the above web.config element to:

 <add name="X-Frame-Options" value="SAMEORIGIN" />

Upvotes: 2

Related Questions