Loading

诡异~~ASP.NET 程序 无法上传文件 (这个..自己大意造成的嘛~~)

现在VS自带的ASP.NET 服务器也不管用鸟、、·~

 

系统也还原过,另一个程序则没有这样的问题,

如图:Request.Files.AllKeys.Count始终为0

开始以为是没有更新生成代码,页面名称和页面类名称也换过 问题依旧,

后来使用VS自带的ASP.NET服务器进行调试没有问题。。。

文件目录权限也都给了上传控件使用的是<input type="file" />并且放在Table里,

也换过Server Control ,如果是服务器控件的话选择文件提交后调试发现控件的FileName属性为空。。

 

另外:还是这个页面之前遇到过表单填写的内容提交到后台居然全是空。。然后莫名其妙的好了,现在只剩下文件这块

 

        <tr>
            
<td height="25" width="30%" align="right">
                项目照片 :
            
</td>
            
<td height="25" id="profiles" width="*" align="left">
                
<asp:FileUpload ID="FileUpload1" runat="server" />
                
<br />
                
<input id="File2" type="file" />
                
<br />
                
<input id="File3" type="file" />
                
<br />
                
<input id="File4" type="file" />
                
<br />
            
</td>
        
</tr>

 

 

后台代码
       //上传图片
        
        HttpFileCollection files 
= Request.Files;
        
string filexts = ".jpg.jepg.png";
        
for (int i = 0; i < files.Count; i++)
        {
            
//最大一兆,大于1M的将会被忽略
            if (filexts.Contains(System.IO.Path.GetExtension(files[i].FileName).ToLower()) && files[i].ContentLength < 1024 * 1024)
            {
                files[i].SaveAs(
string.Format(Server.MapPath("/Tendersimg/{0}/{1}"), model.ID, files[i].FileName));
            }
        }
        FileUpload1.SaveAs(
string.Format(Server.MapPath("/Tendersimg/{0}/{1}"), model.ID, FileUpload1.FileName));        

 即时调试信息:

分别输出了Request.Form["File2"],FileUpload1和Request.Files 

代码
Request.Form["File2"]
null
FileUpload1
{System.Web.UI.WebControls.FileUpload}
    
base {System.Web.UI.WebControls.WebControl}: {System.Web.UI.WebControls.FileUpload}
    FileBytes: {
byte[0]}
    FileContent: {System.IO.Stream.NullStream}
    FileName: 
""
    HasFile: 
false
    PostedFile: 
null
Request.Files
{System.Web.HttpFileCollection}
    
base {System.Collections.Specialized.NameObjectCollectionBase}: {System.Web.HttpFileCollection}
    AllKeys: {
string[0]}

 

 貌似找到原因了。。。

这个项目使用了别人的源码。。

他在web.config里配置了HttpUploadModule......

        <httpModules>
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add name="HttpUploadModule" type="X.Upload.HttpUploadModule, X.Upload" />
            <add name="Spaces" type="X.XHttpModule, x" />
        </httpModules>

 

 

posted @ 2010-07-07 10:11  韩严重  阅读(746)  评论(4编辑  收藏  举报