I am trying to stop this warning in IIS and I am reading that I should check this object IsClientConnected
before I call TransmitFile(filename)
. Is this correct or is Another way to correct this ?
IIS exception
Exception information: Exception type: HttpException Exception message: The remote host closed the connection. The error code is 0x800703E3. at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean ?throwOnDisconnect)
if (context.Response.IsClientConnected)
{
context.Response.Clear();
context.Response.ClearContent();
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.AddHeader("Expires", "-1");
context.Response.ContentType = "application/pdf";
context.Response.TransmitFile(filename);
context.Response.Flush();
context.Response.End();
}
else
{
context.Response.End();
}
updated Code
try
{
context.Response.Clear();
context.Response.ClearContent();
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.AddHeader("Expires", "-1");
context.Response.ContentType = "application/pdf";
context.Response.TransmitFile(filename);
context.ApplicationInstance.CompleteRequest()
//context.Response.Flush();
//context.Response.End();
}
catch (HttpException hex)
{
}
This error implies that there is a Runtime Exception in your code. Usually, when hosting your app through the IIS there are such errors which will close the connection immediately.
You should debug your code by attaching to the process w3wp.
By navigating in Visual Studio to:
---> DEBUG
---> Attach to process
---> choose w3wp.exe
---> attach to process
The troubleshooter implies you to check the IsClientConnected
object because it is the most common issue that will likely to cause the exception - if you are trying to call the client which does not exists (IsClientConnected
is null
for example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With