ASP.NET session has expired or could not be found in webforms app inside an iframe

22 Views Asked by At

I´m tring to show a report using the reportviewer control in a webforms application inside an iframe and I´m geting the error "ASP.NET session has expired or could not be found" I´ve tried all the methods I´ve found in the web to solve this error with no success. I need a clue. It seems to be something related to cors policies but I´m not sure right now.

My code is very simple: This is the aspx page

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <rsweb:ReportViewer AsyncRendering="false" KeepSessionAlive="false" ID="ReportViewer1" runat="server" Width="100%" Height="100%" SizeToReportContent="True" ProcessingMode="Remote">
                 <ServerReport  ReportPath="/xxx/xxx"  ReportServerUrl="http://xxxx.com/ReportServer/" />
               
            </rsweb:ReportViewer>
        </div>
    </form>
</body>
</html>

This is the code behind

using Microsoft.Reporting.WebForms;
using Microsoft.Reporting.WinForms;
using Microsoft.ReportingServices.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SSRSViewer
{
    public partial class Viewer : System.Web.UI.Page
    {
        public string reporte;
        protected void Page_Load(object sender, EventArgs e)
        {
            ReportViewer1.KeepSessionAlive = false;
            ReportViewer1.AsyncRendering = false;
        }
        protected void Page_Init(object sender, EventArgs e)
        {
 
            ReportViewer1.ProcessingMode = ProcessingMode.Remote; // ProcessingMode will be Either Remote or Local

            ReportViewer1.KeepSessionAlive = false;

            ReportViewer1.AsyncRendering = false;

            string path = Request.QueryString["path"];
            reporte = path;

            if (path != null)
            {


                ReportViewer1.ServerReport.ReportPath = reporte; //Passing the Report Path               


            }
            ReportViewer1.ServerReport.Refresh();
        }

    }

and this is the web config

<?xml version="1.0" encoding="utf-8"?>
<!--
  Para obtener más información sobre cómo configurar la aplicación ASP.NET, visite
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
      <sessionState timeout ="120" mode="InProc" cookieless="false" />
      <identity impersonate="true" />
      
      <compilation debug="true" targetFramework="4.7.2">
      <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91" />
      </buildProviders>
      <assemblies>
        <add assembly="Microsoft.ReportViewer.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91" />
        <add assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91" />
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.7.2" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Optimization" />
      </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
      </controls>
    </pages>
    <httpHandlers>
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91" validate="false" />
    </httpHandlers>
      <httpCookies httpOnlyCookies="false" requireSSL="false"/>
      <customErrors mode="Off"/>
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Web.Infrastructure" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
  <system.webServer>
      <httpProtocol>
          <customHeaders>
              <add name="Access-Control-Allow-Methods" value="*" />
              <add name="Access-Control-Allow-Headers" value="*" />
          </customHeaders>
          </httpProtocol>
      <!--<httpProtocol>
          <customHeaders>
              <add name="p3p" value="CP=&quot;IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT&quot;"/>
          </customHeaders>
      </httpProtocol>-->
    <validation validateIntegratedModeConfiguration="false" />
    <!--<modules runAllManagedModulesForAllRequests="true" />-->
    <handlers>
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </handlers>
  </system.webServer>
</configuration>

I´ve tried this also

<sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424" timeout="120"/>

Both, application and report server are in the same server.

And I get an error when calling the report page:

No se puede realizar una solicitud de estado de sesión al servidor de estado de sesión. Compruebe que el servicio de estado ASP.NET se ha iniciado y que los puertos de cliente y servidor son los mismos. Si el servidor se encuentra en un equipo remoto, compruebe el valor de HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection para asegurarse de que acepta más solicitudes. Si el servidor se encuentra en el equipo local y si el mencionado valor del registro no existe o está establecido en 0, la cadena de conexión del servidor de estado debe utilizar 'localhost' o '127.0.0.1' como nombre de servidor.

Thanks for any support

0

There are 0 best solutions below