how to upload large files via fileupload controller in asp.net - c#

I am using file upload controller for uploading documents.Here when I'm using files of size say 30mb I'm getting an error saying
"The connection to the server was reset while the page was loading.".
Its not even going to the upload button click event.
File upload controller working fine for files having smaller size.
I'm uinsg VS2005 and C#.

you have to use httpruntime module for that, Use MaxRequestLength Property, in the configuration section of web.config file.
MaxRequestLength Property you may use code like this,
<configuration>
<system.web>
<httpRuntime maxRequestLength="31457280" executionTimeout="36000" />
</system.web>
</configuration>

add this to your web config
<configuration>
<system.web>
<httpRuntime maxRequestLength="31457280" />
</system.web>
</configuration>

Related

How do I fix the custom errors?

I keep getting this error when trying to run my system
<system.web>
<customErrors mode="Off"/>
</system.web>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.html"/>
</system.web>
First of all, enable the details of this specific error message by putting the "customErrors" tag in your "web.config" file like this:
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Now you will get the exact error in your code and you can fix that specific error.
For security reasons, your code will not be shown in the browser for end user until you have not enabled CustomError mode="Off" in web.config file.
For security reasons .NET-Websites shows complete exceptions only, if you call them locally. To see the error message you have to choices:
Call the website through a browser on the Server (of course not possible, if you deploy to a Azure WebApp, but e.g. in a VM)
Add the first of your snippets (customErrors mode="Off") to your web.config. Then you'll see the complete exception even remotly over the network. My advice would be to set it back to the default setting after you've seen and fixed the error.

Change maximum request length in asp.net mvc without modifying web.config

As the question suggest is it possible to change the maximum request length in an asp.net mvc project without modifying the web.config file?
The project is on several client servers which I don't want to have to manually change for each one so hoping I can put something in global.asax to write it instead or similar?
EDIT:
OR is it possible to add another config file with just the settings I want to overwrite?
I don't think that's possible, as the web config stores the configuration values that your application uses to define how it behaves - in this case, the length of the data you require to be passed on.
You would need to modify the web.config as follows:
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>
And if you are on IIS7 above, the following needs to be configured as well:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
Additional Note: maxAllowedContentLength is measured in bytes while maxRequestLength is measured in kilobytes
Some options you have are:
Powershell script that would read your web.config files on the different servers and update the configuration values accordingly.
Uploading the web config directly via FTP or publish.
Modifying the web config directlyon the server instance.

Web.Release.Config authentication attribute

I defined a WebApi which takes the credetianls from the browser, it works.
After deploying it I have to edit the Authentication on the server from Anonymouns to Windows. I tried to add <authentication mode="Windows"/> to the Web.Config.Release but it doesn't change...
Why? Suggestions?
The .Release.Config file is not a .Config file as such - it's a file that describes how to transform the default Web.Config file into a new Web.Config file for release.
So, you don't simply add nodes to it - you need to specify the modifications you want to make using the defined syntax for this - see https://msdn.microsoft.com/library/dd465318(v=vs.100).aspx
In your case, you probably want something like:
...
<system.web>
<authentication mode="Windows" xdt:Transform="SetAttributes" />
</system.web>
...

Why does setting shadowCopyBinAssemblies="false" have no effect?

I'm trying to turn off shadow copying in IIS to improve performance in production.
But adding that in my web.config has no effect. Here's my web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<hostingEnvironment shadowCopyBinAssemblies="false" />
</system.web>
</configuration>
When I hit the URL it takes just as long the first time, and
files still appear in
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
so it appears to have no effect.
IIS 7.5 and Windows 7. I'm testing with a tiny Hello World ASPX page.
Any ideas why this isn't working? Is this setting overridden somewhere?

Validation of viewstate MAC failed, tried generating machine key

Server Error in '/' Application.
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
I've looked through countless of previous questions and I haven't managed to get it working.
I've edited my web.config file and included a generated key at no success.
Web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<machineKey validationKey="E91A16E07A8D628F1F1397962336B0C63B6DC45B8EB3D16BBD5E5761DD8AE462C04C1CC215904FF0353E84EF8194B48682114C72CF8E10F5295E5ADF36DBC520" decryptionKey="EFA118DF00BFB8206F24A1BB4AF7D18FBD6A605B44789E9048D8127FFF950A09" validation="SHA1" decryption="AES" />
<httpRuntime />
<pages enableViewStateMac="true" />
<customErrors mode="Off" />
<compilation targetFramework="4.0" debug="true" />
<authorization>
<allow users="*" />
<deny users="?" />
</authorization>
</system.web>
</configuration>
This happens when I postback to another page!
Instead of using <form action="..."> to perform a cross-page post back, try changing your submit button to read <asp:Button runat="server" postbackurl="...">. Using the PostBackUrl property is the officially supported way to perform a cross-page post back, as it sets a flag in the request telling the destination page to ignore the __VIEWSTATE field.
The main problem lies in the Application Pool of your website.Configure your website to use the proper .NET Framework version (i.e. v4.0) under the General section of the Application Pool related to your website.
Under the Process Model, set the Identity value to Network Service.Close the dialog box and right-click your website and select Advanced Settings... from the Manage Website option of the content menu. In the dialog box, under General section, make sure you have selected the proper name of the Application Pool to be used.
Your website should now run without any problem.Hope this helps you overcome this error.

Categories