ashx接收html表单数据,新手求救:ashx接收表单/图片的问题

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

我的前台是html5中有个表单

后台是windows 2008 server IIS7.5的服务器

using System;

using System.Web;

using System.IO;

public class UploadFile : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType = "text/plain";

HttpPostedFile f1 = context.Request.Files["f1"];

String fileExt = System.IO.Path.GetExtension(f1.FileName);

System.Drawing.Image image = System.Drawing.Image.FromStream(f1.InputStream);

int newWidth = 300, newHeight = 200;

if ((decimal)image.Width / image.Height > (decimal)newWidth / newHeight)

{

newHeight = Convert.ToInt32((decimal)image.Height * newWidth / image.Width);

}

else if ((decimal)image.Width / image.Height < (decimal)newWidth / newHeight)

{

newWidth = Convert.ToInt32((decimal)image.Width * newHeight / image.Height);

}

System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(newWidth, newHeight);

System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, newWidth, newHeight);

g.DrawImage(image, rectDestination, 0, 0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel);

bmp.Save(context.Server.MapPath("~/") + DateTime.Now.ToString("yyyyMMddHHmmss") + fileExt);

bmp.Dispose();

image.Dispose();

context.Response.Write("OK");

}

public bool IsReusable

{

get

{

return false;

}

}

}

提交表单后出现

/”应用程序中的服务器错误。未将对象引用设置到对象的实例。说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:

行 11: context.Response.ContentType = "text/plain";

行 12: HttpPostedFile f1 = context.Request.Files["f1"];

行 13: String fileExt = System.IO.Path.GetExtension(f1.FileName);

行 14: System.Drawing.Image image = System.Drawing.Image.FromStream(f1.InputStream);

行 15: int newWidth = 300, newHeight = 200;

源文件: d:\wfxt\11\UploadFile.ashx 行: 13

堆栈跟踪:

[NullReferenceException: 未将对象引用设置到对象的实例。] UploadFile.ProcessRequest(HttpContext context) in d:\wfxt\11\UploadFile.ashx:13 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +598 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +170

版本信息: Microsoft .NET Framework 版本:2.0.50727.4927; ASP.NET 版本:2.0.50727.4927

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值