Current filter:
                                You should refresh the page.
                                  • Description:
                                    File uploading is a sensitive procedure in regard to web standards and configurations of modern ASP.NET project templates. Consult the points listed below while implementing file uploading in ASP.NET applications.

                                    This article contains information about frequent situations that may occur when operating:
                                    - ASPxUploadControl in standalone mode
                                    - Embedded into the ASPxHtmlEditor / ASPxFileManager / ASPxSpreadsheet / ASPxRichEdit

                                    - corresponding MVC counterparts.

                                    1. Why may the "The server encountered an internal unspecified error that prevented it from fulfilling the request" error occur?

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

                                    2. Why is it impossible to retrieve the other controls' values when uploading file(s) via the client-side ASPxClientUploadControl.Upload method?

                                    3. Why may the progress panel (ASPxUploadControl.ShowProgressPanel) not show progress information?

                                    4. Why does the progress panel (ASPxUploadControl.ShowProgressPanel) not show progress information under Full .NET Trusted Level (.NET v4)?

                                    5. Why isn't the ASPxUploadControl.FileUploadComplete event raised and the PlatformNotSupportedException thrown when uploading file(s) in the SharePoint 2010 environment?

                                    6. Why may the "Please install Microsoft Silverlight v3 or later to view this content and have an ability to upload files." banner/message appear?

                                    7. Why may the "Not Found" error message appear?

                                    8. Why may the JavaScript "Access is denied" error occur?

                                    9. ASPxUploadControl.ValidationSettings.MaxFileSize / ASPxUploadControl.AdvancedModeSettings.PacketSize

                                    10. Persisting selected files between requests. Working with files/paths programmatically.

                                    Answer:
                                    Important Note:
                                    In order to post selected file(s) to the server memory, the ASPxUploadControl/MVC UploadControl Extension should be placed into the form tag:
                                    WebForms:

                                    [ASPx]
                                    <form ... runat="server"> <dx:ASPxUploadControl ...> </dx:ASPxUploadControl> </form>

                                    MVC:

                                    [C#]
                                    @using(Html.BeginForm(...)) { Html.DevExpress().UploadControl(settings => { ... }).GetHtml() }
                                    [VB.NET]
                                    @Using Html.BeginForm() Html.DevExpress.UploadControl(...).GetHtml() End Using

                                    1. Why may the "The server encountered an internal unspecified error that prevented it from fulfilling the request" error occur?

                                    1.1. This issue usually occurs when the total request length exceeds the maximum allowed via the "system.web > httpRuntime > maxRequestLength" Web.config key. To resolve this issue, increase the value of this key:

                                    [XML]
                                    <system.web> <httpRuntime maxRequestLength="4096" /> ... </system.web>

                                    For IIS 7+ it is also necessary to increase the value of the "system.webServer" > security > requestFiltering > maxAllowedContentLength" key as well:

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

                                    See the Uploading Large Files help topic for more information.
                                    As an alternative solution, it is possible to use the "Advanced" upload mode (ASPxUploadControl.UploadMode = Advanced), which requires Silverlight plug-in v3+ to be installed in end-user browsers.
                                    See the Advanced Upload Mode help topic regarding this.

                                    1.2. This situation can also occur when a web server returns unexpected response/code.
                                    Example: Some authorization code/logic executes a redirect to a login form when the Session Timeout is expired while handling the ASPxUploadControl request. In this case, it is recommended to set the ASPxUploadControl.FileUploadMode to "OnPageLoad" and upload file(s) during the entire page postback (instead of using the client-side ASPxClientUploadControl.Upload method).

                                    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:

                                    [XML]
                                    <trace enabled="true" pageOutput="true" mostRecent="true" />

                                    When tracing is enabled, ASP.NET adds all debug information at the end of Response.StreamOut. It also occurs on callbacks when DevExpress control expects its JSON string. Since this string contains "alien" information, our scripts can not parse it correctly. In this case, the only solution is to disable tracing.

                                    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?

                                    When, for example, the total request length exceeds the maximum allowed length (the most frequent case), the web server terminates this request prior to executing our code and we return a general error message.
                                    Refer to the S171878: ASPxUploadControl - Provide a public property for the "UnspecifiedError" text report to find a sample project with a possible solution.

                                    The only way to catch/diagnose internal server exceptions is handling the Application_Error event in the Global.asax file:

                                    [C#]
                                    void Application_Error(object sender, EventArgs e) { HttpServerUtility server = HttpContext.Current.Server; Exception exception = server.GetLastError(); System.Diagnostics.Debug.WriteLine(exception.Message); if (exception.InnerException != null) System.Diagnostics.Debug.WriteLine(exception.InnerException.Message); }
                                    [VB.NET]
                                    Private Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) Dim server As HttpServerUtility = HttpContext.Current.Server Dim exception As Exception = server.GetLastError() System.Diagnostics.Debug.WriteLine(exception.Message) If exception.InnerException IsNot Nothing Then System.Diagnostics.Debug.WriteLine(exception.InnerException.Message) End If End Sub

                                    In addition, examine network requests initiated by UploadControl during uploading and check the corresponding responses. Use recommendations from the Evaluating network performance article for this purpose.

                                    2. Why is it impossible to retrieve the other controls' values when uploading file(s) via the client-side ASPxClientUploadControl.Upload method?
                                    By default, the ASPxUploadControl.FileUploadMode property is set to "BeforePageLoad". In this case, use the ASPxUploadControl uploads file(s) before a page control's hierarchy is created.
                                    Set the ASPxUploadControl.FileUploadMode property to "OnPageLoad" in order to be able to get the other controls' values.
                                    See the UploadControlFileUploadMode Members help topic for more information.

                                    3. Why may the progress panel (ASPxUploadControl.ShowProgressPanel) not show progress information?

                                    3.1. This issue occurs if the ASPxUploadProgressHttpHandler element is not registered in the Web.config. This element is automatically registered in the configuration file when ASPxUploadControl is placed onto a form in the Design View.
                                    If this element is missing, define it manually according to instructions from the ASPxUploadProgressHttpHandler > Registration help topic. Make sure that both "verb" (GET and POST) actions are allowed.

                                    3.2. The ASPxUploadControl.ShowProgressPanel = True feature is available when the application is running under the Full .NET Trusted Level. ASPxUploadControl uses the standard HttpWorkerRequest type for requesting progress information, which requires Full .NET Trusted Level permissions.
                                    To resolve potential upload problems when operating under the Medium .NET Trusted Level, set ASPxUploadControl.ShowProgressPanel property to False.
                                    As an alternative solution, it is possible to use the "Advanced" upload mode (ASPxUploadControl.UploadMode = Advanced), which requires Silverlight plug-in v3+ to be installed in end-user browsers.
                                    See the Advanced Upload Mode help topic regarding this.

                                    4. Why does the progress panel (ASPxUploadControl.ShowProgressPanel) not show progress information under Full .NET Trusted Level (.NET v4)?
                                    This problem occurs when, running under IIS 7 (.NET v4), the Application Pool is set to "Integrated" mode. To resolve this issue, switch the Application Pool to the "Classic" mode (or disable the ShowProgressPanel feature).

                                    5. Why isn't the ASPxUploadControl.FileUploadComplete event raised and the PlatformNotSupportedException thrown when uploading file(s) in the SharePoint 2010 environment?
                                    ASPxUploadControl uses the standard HttpWorkerRequest type for requesting progress information. This object writes data to the HttpRequest.ServerVariables collection, which does not support the Windows 2008 R2 x64 platform.
                                    To avoid these problems, set ASPxUploadControl.ShowProgressPanel property to False.

                                    6. Why may the "Please install Microsoft Silverlight v3 or later to view this content and have an ability to upload files." banner/message appear?
                                    This banner/message appears if the Advanced Upload Mode is enabled via the ASPxUploadControl.UploadMode=Advanced or ASPxUploadControl.AdvancedModeSettings.EnableMultiSelect=True properties, and the end-user's browser does not have the Microsoft Silverlight plugin installed.
                                    If the end-user browser may not have the Microsoft Silverlight plugin installed and you do not want such a banner/message to appear, turn off the Advanced Upload Mode via the mentioned properties (ASPxUploadControl.UploadMode=Standard or ASPxUploadControl.AdvancedModeSettings.EnableMultiSelect=False)
                                    See the Advanced Upload Mode help topic regarding this.

                                    7. Why may the "Not Found" error message appear?
                                    This issue occurs when the ASPxUploadControl.ShowProgressPanel = True or the Advanced / Auto Upload Mode is enabled and if the ASPxUploadProgressHttpHandler element is not registered in the Web.config. This element is automatically registered in the configuration file when ASPxUploadControl is placed onto a form in the Design View.

                                    If this element is missing, define it manually according to instructions from the ASPxUploadProgressHttpHandler > Registration help topic. Make sure that both "verb" (GET and POST) actions are allowed.

                                    In addition, make sure that there are no special rules for routing the "{resource}.ashx" URLs. If so, add the corresponding exception, like it is done in the DevExpress ASP.NET MVC Project Template:

                                    MVC 3:

                                    Global.asax.cs:

                                    [C#]
                                    protected void Application_Start() { ... RegisterRoutes(RouteTable.Routes); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{resource}.ashx/{*pathInfo}"); ... }

                                    MVC 4+:

                                    Global.asax.cs:

                                    [C#]
                                    protected void Application_Start() { ... RouteConfig.RegisterRoutes(RouteTable.Routes); }

                                    /App_Start/RouteConfig.cs:

                                    [C#]
                                    public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{resource}.ashx/{*pathInfo}"); ... }

                                    8. Why may the JavaScript "Access is denied" error occur?

                                    8.1. The X-Frame-Options custom header with a "DENY" value used (globally - at the IIS level, locally - at the application level). The ASPxUploadControl uses an iframe HTML element internally, so it is affected by this restriction as well.

                                    It is possible to either set this header value to "SAMEORIGIN" or remove this header. You can do it at the application level in the Global.asax file:

                                    [C#]
                                    protected void Application_PreSendRequestHeaders(object sender, EventArgs e) { HttpContext.Current.Response.Headers.Remove("X-Frame-Options"); HttpContext.Current.Response.AddHeader("X-Frame-Options", "SAMEORIGIN"); }
                                    [VB.NET]
                                    Protected Sub Application_PreSendRequestHeaders(ByVal sender As Object, ByVal e As EventArgs) HttpContext.Current.Response.Headers.Remove("X-Frame-Options") HttpContext.Current.Response.AddHeader("X-Frame-Options", "SAMEORIGIN") End Sub

                                    Also, it is possible to set up this setting for an IIS server in web.config:

                                    [XML]
                                    <system.webServer> ... <httpProtocol> <customHeaders> <add name="X-Frame-Options" value="SAMEORIGIN" /> </customHeaders> </httpProtocol> ... </system.webServer>

                                    8.2.  When implementing some kind of a custom "Browse" button / raising "click" on the HTML <input type="file" /> element (for example, obtained via the ASPxClientUploadControl.GetFileInputElement(0).click() method).

                                    This scenario is not supported in IE because of its security restrictions:
                                    getting access is denied error on IE8

                                    Starting with version 15.1, it is possible to implement a custom "Browser Dialog Trigger". See the S173522: ASPxUploadControl - Provide the capability to call a file select dialog without clicking the "Browse" button or input field ticket to learn more about related programmatic options.

                                    9. ASPxUploadControl.ValidationSettings.MaxFileSize / ASPxUploadControl.AdvancedModeSettings.PacketSize

                                    9.1.  Why may the following errors occur?

                                    "The ValidationSettings.MaxFileSize property's value exceeds the Web.Config's maxRequestLength setting. For the ASPxUploadControl's built-in validation to work correctly, the ValidationSettings.MaxFileSize property should be less than the Web.config's maxRequestLength setting." (the UploadControl_MaxFileSizeExceeded constant)

                                    "The AdvancedModeSettings.PacketSize property's value exceeds the Web.Config's maxRequestLength setting. For ASPxUploadControl to work correctly, the AdvancedModeSettings.PacketSize property should be less than the Web.config's maxRequestLength setting."  (the UploadControl_PacketSizeExceeded constant)

                                    These errors indicate that the corresponding ASPxUploadControl's (for standalone mode or when it is being used as an uploading engine of a complex control) properties are NOT configured correctly (i.e., they allow posting request data whose volume is greater than it is allowed by an application's configuration). Follow the suggested instructions and make sure that these settings/values are less than the Web.config's maxRequestLength setting.

                                    9.2. Why may the ASPxUploadControl.ValidationSettings.MaxFileSize property work improperly

                                    This property specifies if a file is valid (according to the other ASPxUploadControl.ValidationSettings as well) only after uploading, and the corresponding controls/EventArgs property are set then.
                                    See the ASPxUploadControl.ValidationSettings.MaxFileSize help topic for more information.

                                    If its value is greater than the Web.config maxRequestLength setting (i.e., allowed by the application's configuration), one of the above configuration errors occur.

                                    At the same time, if the file size is greater than the maxRequestLength, the file is not uploaded. The web server terminates this request prior to executing our code and we return a general error message.

                                    10.  ASPxUploadControl renders the standard <input type="file" /> tag/element that does not allow performing certain operations (such as persisting selected files between requests, working with files/paths programmatically, etc.) because of the browsers security policy. Please refer to the (INPUT type=file) MSDN article for more information.

                                • Douglas Cunningham 12.25.2012

                                  Thank you so much. I even looked at that, and thought the change had stuck. Thanks so much, you guys are awesome. HAve a great holiday

                                • Jay Karcher 10.31.2014

                                  Thanks a million for this article!! I created a separate project to test the uploader and when inserting it into my real project I could not figure out what the difference was. It was the missing rule for the routing.

                                0 Solutions

                                Creation Date Importance Sort by