【发布时间】:2012-01-03 12:44:13
【问题描述】:
我正在创建一个图像结果.. 但是“公共覆盖 void ExecuteResult (ControllerContext Context)”说:没有找到合适的方法来覆盖。
我的班级看起来像这样..
public override void ExecuteResult(ControllerContext Context)
{
byte[] bytes;
string contentType = GetContentTypeFromFile();
//if there's no context, stop the processing
if (Context == null)
{
throw new ArgumentNullException("context");
}
//check for file
if(File.Exists(_path)){
bytes = File.ReadAllBytes(_path);
}
else{
throw new FileNotFoundException(_path);
}
//
HttpResponseBase response = Context.HttpContext.Response;
response.ContentType = contentType;
MemoryStream imageStream = new MemoryStream(bytes);
byte[] buffer = new byte[4096];
while (true)
{
int read = imageStream.Read(buffer, 0, buffer.Length);
if (read == 0)
break;
response.OutputStream.Write(buffer, 0, read);
}
response.End();
}
【问题讨论】:
标签: image asp.net-mvc-3 overriding