Pass Windows User (domain\userid) to report url in ASCX page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ismailc
    New Member
    • Sep 2006
    • 200

    Pass Windows User (domain\userid) to report url in ASCX page

    Good day, not sure what to do.

    I have an ascx page with the code displaying the user logged in, i created an iframe src displaying a report but i want to add the logged in id as parameter but can't determine the code value.

    ascx page code
    Code:
    <%@ Control Language="c#" AutoEventWireup="True" Codebehind="Header.ascx.cs" Inherits="FlowCentric.Net.Navigator.Header" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
    <tr>            
    <td><asp:Label id="[B]lblLogin[/B]" runat="server">Welcome</asp:Label></td>
     </tr>
    the iframe report i add & add the user parameter to the label's lblLogon value.
    Code:
     <IFRAME id="frame1" src="http://biweb/reportserver?[B]&User=lblLogin[/B]"</IFRAME>
    Please Assist, totally lost
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Get rid of the "&"....it should be like:
    Code:
    <IFRAME id="frame1" src="http://biweb/reportserver?User=lblLogin"</IFRAME>
    Another problem you're having is that you aren't actually passing the innerHtml of the Label...

    I would recommend using a Session variable instead of passing it via the URL because it's going to be complicated.... it's going to require using JavaScript to retrieve the innerHtml of the <span> element (Labels are rendered as <span> elements) to retrieve the login name. Then you'll have to use JavaScript to set the src of the iFrame element.

    It's doable but using Session variables is a lot easier and cleaner.

    -Frinny

    Comment

    • ismailc
      New Member
      • Sep 2006
      • 200

      #3
      Thank You vey much - tried a few things.

      But i will try & and get the code for asp to determine the windows user & pass as a parameter for the report.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I don't think you understood.
        It's more than just removing the "&".....

        If you're going to pass a value using the URL you need to retrieve the value Client Side using JavaScript and then set the src of the iFrame using JavaScript.

        Comment

        • ismailc
          New Member
          • Sep 2006
          • 200

          #5
          Pass Windows User (domain\userid) to report url in ASCX page

          Good day, This is linked to my previous post.

          I want to display the Windows user logged on to the PC (domain\userid) and add to the report URL.

          I have searched:
          Code:
          <% Response.Write(Request.ServerVariables("AUTH_user")) %>
          Now i want to display & add to url:
          Code:
          <%@ Control Language="c#" AutoEventWireup="True" Codebehind="Header.ascx.cs" Inherits="FlowCentric.Net.Navigator.Header" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
          <table><tr>
          <td><asp:Label id="lblLogin" runat="server">We</asp:Label></td>               
          </tr></table>
          
           <IFRAME id="frame1" src="http://biweb/reportserver?&User= <% Request.ServerVariables("AUTH_user") %>"></IFRAME>	
           
          
          <% Response.Write(Request.ServerVariables("LOGon_user")) %>  <!-- this does not work
          Please Assist!

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            I've merged your questions together.
            Is "http://biweb/reportserver" in the same web application as the other page?
            In that case your user's information should already be available in the ReportServer.as px page.

            -frinny

            Comment

            • ismailc
              New Member
              • Sep 2006
              • 200

              #7
              Thank You for the help, the reports are from the BiReportServer

              where would i find & extract the information from the reportserver.as px.

              I need to pass the loged in user id to the report parameter.

              Please Assist with detail code.

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Are both pages part of the same web application??

                If so, and you're using Windows Authentication, then you should be able to access the user information using the HttpContext.Use r property in both pages.

                Once a user has logged in a Principal Object is created to represent the user. This Principal Object is recreated every time the user accesses a page in the web application. It's created before your code is accessed so that ASP.NET can determine whether or not the user has permissions to access your code. This Principal Object (which represents your user) is stored in the HttpContext.Use r property which is available to you through out your web application (in any page).

                This contains the User's ID along with other user information.

                Comment

                • ismailc
                  New Member
                  • Sep 2006
                  • 200

                  #9
                  Unfortnuately they are different servers.

                  Comment

                  • ismailc
                    New Member
                    • Sep 2006
                    • 200

                    #10
                    Any other ideas, please?

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      Well you need to append the ID of the user stored in the Label (the <span> element representing the Label) to the src (URL) of the iFrame.


                      To do this you're going to have to use JavaScript.

                      You could do something like:

                      Code:
                      <script type="text/javascript">
                        function setIFrameSource()
                        {
                           var labelElement = document.getElementById('<%=Request.ServerVariables("AUTH_user")');
                           var newUrl = "http://biweb/reportserver?UserID=" + labelElement.innerHTML;
                      
                           var iFrameElement = document.getElementById("frame1");
                           iFrameElement.src = newUrl;
                        }
                      </script>
                      You'd call it during the <body> element's onload event:

                      Code:
                      <body onload="setFrameSource">
                      Please note that spaces will mess up your URL...this means that if your user name has a space you need to remove them and replace it with %20.

                      Also please note that you have to grab the UserID value from the URL. The easiest way to do this is using Request.Params( "UserID"). Always validate this information.

                      Comment

                      • ismailc
                        New Member
                        • Sep 2006
                        • 200

                        #12
                        Hi,

                        It does not like the line
                        var labelElement = document.getEle mentById('<%=Re quest.ServerVar iables("AUTH_us er")');

                        no error message, only incorrect syntax

                        regards

                        Comment

                        • Frinavale
                          Recognized Expert Expert
                          • Oct 2006
                          • 9749

                          #13
                          Hehe, well of course it's incorrect...the word processor here on bytes doesn't automatically close tags like Visual Studio does


                          Close the "<%= " with "%>".

                          Like this:

                          Code:
                          <script type="text/javascript">
                            function setIFrameSource()
                            {
                               var labelElement = document.getElementById('<%=Request.ServerVariables("AUTH_user") %>');
                               var newUrl = "http://biweb/reportserver?UserID=" + labelElement.innerHTML;
                          
                               var iFrameElement = document.getElementById("frame1");
                               iFrameElement.src = newUrl;
                            }
                          </script>
                          My syntax isn't always going to be 100% because I'm just writing quick examples of code...you're going to have to check it and even correct it sometimes to make sure it's working ;)

                          But the above code is incorrect anyways (because you don't have a Label with the ID that is UserID...instea d it should be Label.ClientID) . You don't actually need to grab the user ID from the label...you can just simply grab it from the server.


                          Change it to:


                          Code:
                          <script type="text/javascript">
                            function setIFrameSource()
                            {
                              
                               var newUrl = "http://biweb/reportserver?UserID=" + "<%=Request.ServerVariables("AUTH_user") %>";
                          
                               var iFrameElement = document.getElementById("frame1");
                               iFrameElement.src = newUrl;
                            }
                          </script>
                          Please note that the ASP code "<%=" is the same as having "<% Response.Write( ) %>"...it's just the short hand version.

                          Comment

                          • ismailc
                            New Member
                            • Sep 2006
                            • 200

                            #14
                            Thank You i really appreciate your help & am very gratefull.

                            Unfortunately still struggling:

                            It still complains about the 1st line in the javascript:
                            Code:
                            <%@ Control Language="c#" AutoEventWireup="True" Codebehind="Header.ascx.cs" Inherits="FlowCentric.Net.Navigator.Header" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
                            
                            
                            <script type="text/javascript"> 
                              function setIFrameSource() 
                              { 
                            
                             [B]    var newUrl = "http://biweb/reportserver?&User=" + <% Response.Write(Request.ServerVariables("AUTH_user")) %>; [/B]
                              
                                 var iFrameElement = document.getElementById("frame1"); 
                                 iFrameElement.src = newUrl; 
                              } 
                            </script>
                            
                            <body onload="setFrameSource">
                            
                            <table><tr>            
                            <td><asp:Label id="lblLogin" runat="server">Wel</asp:Label></td>               
                             </tr></table>
                            </body>
                            Please Assist, my only hope - i dont know the code at all & only know the reports.

                            Regards

                            Comment

                            • Frinavale
                              Recognized Expert Expert
                              • Oct 2006
                              • 9749

                              #15
                              Why do you have an "&" in there?
                              Also, you need quotes around:

                              <% Response.Write( Request.ServerV ariables("AUTH_ user")) %>

                              That is going to write text into the place where the Response.Write line is.
                              You need to specify that this text should be treated as a literal (a String) by putting quotes around it:

                              "<% Response.Write( Request.ServerV ariables("AUTH_ user")) %>";

                              Comment

                              Working...