In this post, I will tell you about fix System.Web.UI.ViewStateException: Invalid viewstate or System.Web.HttpException: The client disconnected exception Response.IsClientConnected Property ASP.NET 4.8.What is HttpResponse.IsClientConnected Property: HttpResponse.IsClientConnected used to gets a quality demonstrating whether the customer is still joined with the server.

The accompanying illustration utilizes the IsClientConnected property to check whether the customer that is asking for the page remains connected to the server. IfIsClientConnected is genuine, the code calls the  Redirect  technique, and the client will see an alternate page. In the event that IsClientConnected is false, then the code calls the End system and all page handling is ended.

 

And here is code that I used:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Fix System.Web.UI.ViewStateException
    </title></head>
<body>
    <form id="form1" runat="server">
    <div>Welcome</div>
    </form>
</body>
</html>

C#
public partial class ClientDisconnected : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Check whether the browser(client) remains connected to the server
        if (Response.IsClientConnected)
        {
            // if  browser connected, redirect to the Main.aspx page
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            //if browser is not connected,terminate all response processing.
            Response.End();
        }
    }
}


VB.NET
Public Partial Class ClientDisconnected
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(sender As Object, e As EventArgs)
        'Check whether the browser(client) remains connected to the server
        If Response.IsClientConnected Then
            ' if  browser connected, redirect to the Main.aspx page
            Response.Redirect("~/Main.aspx")
        Else
            'if browser is not connected,terminate all response processing.
            Response.[End]()
        End If
    End Sub
End Class

HostForLIFE.eu ASP.NET 4.8 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.