11

このコードの正しい使用法は何ですか?

httpContext.Response.AddHeader("Content-Disposition", "inline; filename=" + HttpUtility.UrlPathEncode(fileName));
httpContext.Response.ContentType = "image/png";
httpContext.Response.AddHeader("Content-Length", new FileInfo(physicalFileName).Length.ToString());
httpContext.Response.TransmitFile(physicalFileName);
httpContext.Response.Flush();
httpContext.Response.End();  //Use it or not?

.Flush()使うのは本当にいい.End()ですか?

これによると、決して使用Response.End()しないでください(エラーまたはハッキングのシナリオでのみ)

しかし、いくつかの答えでは、それ.End()が推奨されています...?

この記事のように。

それで、使用するのが適切Response.Endかどうか?

4

2 に答える 2

5

Thomas Marquardtによると、絶対に使用しないでくださいResponse.End()。代わりに を使用する必要がありますContext.ApplicationInstance.CompleteRequest()。この記事も確認してください。これは Microsoft KB からのもので、Application.CompleteRequest()代わりにの使用を推奨していますResponse.End()

于 2013-01-28T17:30:51.183 に答える