默认只能上传2M附件, 如何放开限制? (asp.net C#)
对于asp.net,默认只允许上传2M文件,增加如下配置,一般可以自定义最大文件大小.
<httpRuntime executionTimeout="300" maxRequestLength="40960" useFullyQualifiedRedirectUrl="false"/>
我们在上传大文件时都遇到过这样或那样的问题。设置很大的maxRequestLength值并不能完全解决问题,因为ASP.NET会block直到把
整个文件载入内存后,再加以处理。实际上,如果文件很大的话,我们经常会见到Internet Explorer显示 "The page
cannot be displayed - Cannot find server or DNS
Error",好像是怎么也catch不了这个错误。为什么?因为这是个client side错误,server
side端的Application_Error是处理不到的,可以参考这个帖子研究一下产生这个错误的机理。
handling server error when upload file too large
解决的方法是利用隐含的HttpWorkerRequest,用它的GetPreloadedEntityBody 和
ReadEntityBody方法从IIS为ASP.NET建立的pipe里分块读取数据,Chris
Hynes为我们提供了这样的一个方案(用HttpModule),该方案除了允许你上传大文件外,还能实时显示上传进度。
IServiceProvider provider = (IServiceProvider) HttpContext.Current;
HttpWorkerRequest wr = (HttpWorkerRequest) provider.GetService(typeof(HttpWorkerRequest));
byte[] bs = wr.GetPreloadedEntityBody();
....
if (!wr.IsEntireEntityBodyIsPreloaded())
{
int n = 1024;
byte[] bs2 = new byte[n];
while (wr.ReadEntityBody(bs2,n) >0)
{
.....
}
}
感谢Chris Hynes提供了通过HttpModule(Krystalware.HttpUploadManager)实现 ASP.NET大文件上传的代码:
(其中HttpUploadSpike.rar是 ASP.NET大文件上传开源版本[有一些小BUG,修改方法见下文]
SlickUpload-2.5.2.rar是 ASP.NET大文件上传最新的非开源版本)
使用Chris Hynes提供的代码
相关文档:
What is ASP.NET
ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web applications with a minimum of coding. ASP.NET is part of the .NET Framework, and when coding ASP.NET applications you have access to classes in the .NET Frame ......
界面: Default.aspx
界面上添加的控件:
两个TextBox: tEmail(用于输入用户email),tPassword(用于输入注册密码)
一个Button: bReg
一个Label: lLable(用于注册成功后显示应答)
Demo的代码: Default.aspx.cs
我们先把数据的连接字符串写在Web.config里:
<appSettings>
<add key="oracleconn" value= ......
如何给Asp.Net 网站项目打包
1、打开你的项目,在<解决方案管理器>中用鼠标右击你的<解决方案>,选择<添加>-<新建项目>。
2、<添加新项目>对话框中选择<安装和部署项目>-<web安装项目>。(注意:<web安装项目>的存放路径。)
3、vs.net 的窗口左侧会显示<文件 ......
看了那么多,还是亲自动手实践下有效果。
引用 百度 杨云飞ai生活
ASP.NET 2.0 实现伪静态网页方法
方法一:利用Httphandler实现URL重写(伪URL及伪静态)
我们有时候会见到这样的地址:“http://www.huoho.com/show-12-34.html”,你或许认为在站点服务器根目录“/”下存在名为“show- ......