This is a migrated thread and some comments may be shown as answers.

RadScheduler ExporttoPDF error

1 Answer 75 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Grace
Top achievements
Rank 1
Grace asked on 23 Oct 2017, 03:26 PM

I am trying to implement the export to pdf from radscheduler.  In works fine on my local and when I publish to the demo site if I am in HTTP it works fine but if I go to HTTPS it gives the following error.  App logs and server event logs are not giving any more information:

Server Error in '/' Application.

An existing connection was forcibly closed by the remote host
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +249

[IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
   System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +8442161
System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) +57
System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +243
   System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +470
System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) +8572686
   System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) +230
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +645
   System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +9
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +87
   System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) +1467
   System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) +84
System.Net.ConnectStream.WriteHeaders(Boolean async) +816

[WebException: The underlying connection was closed: An unexpected error occurred on a send.]
   System.Net.HttpWebRequest.GetResponse() +8442708
Telerik.Web.UI.Scheduler.SchedulerExporter.GetStyleSheet(String url) +120
Telerik.Web.UI.Scheduler.SchedulerExporter.GetStyleSheetFor(String controlName, Type controlType, Page page, String pathFormatString, String defaultPathFormatString) +318
Telerik.Web.UI.Scheduler.SchedulerExporter.GetStyleSheets(Page page) +99
Telerik.Web.UI.Scheduler.SchedulerExporter.RenderControl(Page page) +695
   Telerik.Web.UI.Scheduler.SchedulerExporter.PdfExportRenderForm(HtmlTextWriter nullWriter, Control form) +154
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +151
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +49
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
   System.Web.UI.Page.Render(HtmlTextWriter writer) +40
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
Telerik.Web.UI.RadAjaxControl.RenderPageInAjaxMode(HtmlTextWriter writer, Control page) +1040
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
   System.Web.UI.Page.Render(HtmlTextWriter writer) +40
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5363

1 Answer, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 02 Nov 2017, 04:59 PM
Hello Grace,

Thank you for the exception details.

Such problems are usually by an incorrectly configured server and some generic connection issues. You can see that the problem is not replicated in the Scheduler - Pdf Export demohttps://demos.telerik.com/aspnet-ajax/scheduler/examples/pdfexport/defaultcs.aspx.

Based on the Stack trace, it seems that the GetStyleSheet method is failing where we only do a standard HttpWebRequest. The error that you observe seems to be a general issue connected with such behavior rather than an issue with the control itself. That is why I would rather recommend you to refer to some more appropriate forum regarding the issue as this one for example: C# System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send.

Also, in order to troubleshoot the method itself I've extracted its logic outside the code of the Scheduler in a TestGetStyleSheet method. 

protected void TestGetStyleSheet(object sender, EventArgs e)
{
    var url1 = Telerik.Web.SkinRegistrar.GetWebResourceUrl(Page, typeof(RadScheduler), "Telerik.Web.UI.Skins.Scheduler.css");
    url1 = UpdateWebResourceUrl(url1);
   
    var styleSheet1 = GetStyleSheet(url1);
   
    var url2 = Telerik.Web.SkinRegistrar.GetWebResourceUrl(Page, typeof(RadScheduler), "Telerik.Web.UI.Skins.Windows7.Scheduler.Windows7.css");
    url2 = UpdateWebResourceUrl(url2);
   
    var styleSheet2 = GetStyleSheet(url2);
}
   
private static string UpdateWebResourceUrl(string path)
{
    var currentContext = System.Web.HttpContext.Current;
    var request = currentContext.Request;
    var schemeAndServer = request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
    var sb = new StringBuilder(schemeAndServer);
   
    sb.Append(path);
    sb.Replace("~", "");
    path = sb.ToString();
    return path;
}
       
private string GetStyleSheet(string url)
{
    var request = (HttpWebRequest)WebRequest.Create(url);
    request.UseDefaultCredentials = true; //Fixes 401 Unauthorized exceptions
    var response = request.GetResponse();
   
    var enc = System.Text.Encoding.UTF8;
    var loResponseStream = new StreamReader(response.GetResponseStream(), enc);
   
    string result = loResponseStream.ReadToEnd();
   
    loResponseStream.Close();
    response.Close();
   
    HttpContext currentContext = System.Web.HttpContext.Current;
   
    string[] splittedResult = result.Split(new string[] { "url('", "')" }, StringSplitOptions.None);
    List<string> splittedUrlsThatNeedsUpdate = new List<string>();
   
    for (int i = 0; i < splittedResult.Length; i++)
    {
        if (splittedResult[i].Contains("WebResource.axd?"))
        {
            if (!splittedUrlsThatNeedsUpdate.Contains(splittedResult[i]))
            {
                splittedUrlsThatNeedsUpdate.Add(splittedResult[i]);
            }
        }
    }
   
    List<string> splittedUrlsUpdated = new List<string>();
    foreach (string item in splittedUrlsThatNeedsUpdate)
    {
        var currentRequest = currentContext.Request;
        var schemeAndServer = currentRequest.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
        var sb = new StringBuilder(schemeAndServer);
   
        sb.Append(currentContext.Request.ApplicationPath);
        sb.Append("/" + item);
        sb.Replace("~", "");
   
        splittedUrlsUpdated.Add(sb.ToString());
    }
   
   
    StringBuilder stringBuilder = new StringBuilder(result);
    for (int j = 0; j < splittedUrlsUpdated.Count; j++)
    {
        stringBuilder.Replace(splittedUrlsThatNeedsUpdate[j], splittedUrlsUpdated[j]);
    }
   
    return stringBuilder.ToString();
}

Attaching the TestGetStyleSheet method to a button click event is one approach to test the method.

Also, I can recommend trying the ClientExportManager to export the Scheduler to PDF as demonstrated in the Scheduler client PDF export with ClientExportManager code library project.

Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Scheduler
Asked by
Grace
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or