Ticket T886545
Visible to All Users

How to access the values stored in HttpContext/Session from client-side while working with the ASP.NET HTML5 End-User Web Report Designer (server-side)

created 5 years ago

Hi team,

My solution is composed by two projects:

  • Client-Side (DevExtreme)
  • Server-Side (Web Report Designer)

My requirement is to pass certain information from session context provided by login process (in client-side) and retrieve it in the CustomReportStorageWebExtension (in server-side) in order to pass that information as parameters to report.

I done this in a prototype based on MVC with Web Report Designer, all integrated in a unique project, and all works fine, you can see the code attached.

But now, I have one solution composed by two projects running in differents domains, and the solution I described above does not working (I think, the reason is due the CORS scenario).

How I can accomplish that requirement in this architecture?

Login Process code:

C#
[HttpPost] public JsonResult OpenSesionUser(string nombreUsuario, string idNivel) { try { if (idNivel != "") { USUARIOS usuario = SessionContext.Current._usuario; NivelUsuarioVM nivelUsuario = NivelUsuarioDAO.GetByUsuarioIdNivelId(usuario, idNivel); if (!NullOrEmptyValidator.IsEmptyEntity(nivelUsuario)) { NivelRepository repo = new NivelRepository(); repo.ValidarAccesibilidad(nivelUsuario); if (!usuario.NIVEL_DEFECTO.Equals(idNivel)) UsuarioDAO.UpdateNivelDefecto(usuario, idNivel); SessionContext.Current._nivelUsuario = nivelUsuario; //Pass object nivelUsuario to context HTTP used by Web Report Designer if (Session["_NivelUsuario"] == null) { Session["_NivelUsuario"] = nivelUsuario.COD_NIVEL; Session["_NombreNivel"] = nivelUsuario.DESCRIPCION_NIVEL; } /////////////////////////////////////////////////////////////////////////////////// SesionDAO.Create(new SESIONES() { IP = IP.GetIpCliente(), ID_NIVEL_USUARIO = nivelUsuario.ID }); FormsAuthentication.SetAuthCookie(nombreUsuario, false); } //Translator.GetAllTraducciones(); } return new OkRequest("ok"); } catch (iSGCASExceptions ex) {...} }

CustomReportStorageWebExtension code:

C#
public override byte[] GetData(string url) { // Get the report's layout from report's storage using (var session = SessionFactory.Create()) { var reportEntity = session.GetObjectByKey<CATALOGO_REPORTES>(url); XtraReport report = new XtraReport(); using (MemoryStream ms = new MemoryStream(reportEntity.LAYOUT)) { report.LoadLayoutFromXml(ms); } try { report.Parameters["Id_Nivel"].Value = HttpContext.Current.Session["_NivelUsuario"]; report.Parameters["Nombre_Nivel"].Value = HttpContext.Current.Session["_NombreNivel"]; } catch { ... }; using (MemoryStream ms = new MemoryStream()) { report.SaveLayoutToXml(ms); reportEntity.LAYOUT = ms.ToArray(); } session.CommitChanges(); return reportEntity.LAYOUT; } }

Regards,
Oscar

Show previous comments (12)
Yaroslav (DevExpress Support) 5 years ago

    >>The kind of data I need to pass are not related with session. These are no sensitive.
    So, what are these parameters and how do you intended to use them further? Note that Web End-User Report Designer will reveal all parameters to the user regardless of their visibility, there's no way of hiding a certain parameter from the UI. I'm asking this question as you specifically mentioned that you'd like to complete this task "without user intervention".

    >>If you have something to update or complete, please, do it.
    What you found is a possible solution, but it will only work for the report that you open by default in code, not for the report that the users opens through the built-in "Open" dialog.

    OP OP
    Oscar Piñones (Opendat) 5 years ago

      Thanks Yaroslav,

      I sorry by didn't be clear about the use scenario of web report designer.

      Here I go to clarify the "use scenario":

      Our customer have two roles for use this tool:

      • The designer, who have permision to create and and assign the report to users whom will consume this reports (final consumer role). Obviously the designer have full permisions to see and modify the parameters. In fact, the designer is the owner and responsible's user of these reports.

      • The final consumer, who have permision only to see the the reports and its data. The parameters what I need are required to complete the underlying query, and this parameters will be hidden for the final consumer. This must be passed by code without final consumer's intervention.

      The list of reports is managed by a form which is out of the web report designer.

      So, the final consumer never, but never will see the web report designer in action, they just will use the web report viewer.

      I hope this is clear for you now.

      Regards,
      Oscar

      OP OP
      Oscar Piñones (Opendat) 5 years ago

        you say:

        You never operate with the XtraReport instance in C# code, it's about JavaScript. In other words, there is no direct way of passing values from the client to the server using the XtraReport.Parameters collection

        So, could you guide me in a way to accomplish that?
        please, it's urgent…

        Regards,
        Oscar

        Answers

        created 5 years ago (modified 5 years ago)

        Finally I can solve my problem.

        First: Encode parameters togheter to reporting name inside variable urlReport, in client-side.

        Second: Pass the encoded variable in argument urlReport of designerOptions object, which is passed through ko with applyBindings (knockout) from devExtreme.

        Third: receive, in server-side, the encoded variable reportUrl in ReportDesignerController (method GetReportDesignerModel) and decode immediately. This mean separate the report name from parameters and create for each parameter one session variable which you can use in the other class, CustomReportStorageWebExtension, method GetData.

        Fourth: Assign each session variable created previously to corresponding parameter in XtraReport.

        And that's all

          created 5 years ago

          Hi Oscar,
          >>The parameters what I need are required to complete the underlying query, and this parameters will be hidden for the final consumer.
          This sounds like you're trying to implement a data access control based on the current user context. In other words, end users shouldn't be able to see one other's data. None of the built-in data connectors allow you to implement this task — there is no automatic data filtering based on the user that is currently logged in.

          >>So, could you guide me in a way to accomplish that?
          Sure. Consider the following solution:
          A report is bound to the ObjectDataSource component that is used to expose the datasource schema in the "Field List" window: Bind a Report to an Object Data Source. However, upon switching to the preview tab, ObjectDataSource is substituted with a real collection of objects that are fetched based on the current user identity. Because of that (even though it's the same report bound to the same class), different users will see different data.
          I've attached a sample project for your reference. It's for ASP.NET Core, but the same approach can be used in an ASP.NET MVC application as well.
          Check the solution and let me know if you have any questions regarding this approach.

          Regards,
          Yaroslav

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.