locked
ReportViewer in Gridview > "The request failed with HTTP status 401: Unauthorized" RRS feed

  • Question

  • User-1312722619 posted

    Hi experts,

    I have a reportviewer control which is running well on a form. I dont receive any error message. I can pass parameters successfully.

    The problem starts after placing Reportview control into a grid. I need several reports for different parameters at the same time. In this case, i receive boring "The request failed with HTTP status 401: Unauthorized" error. There is no reason to receive this message as reportviewer working on the form seperate.

    Is there any restriction not to use ReportViewer in the gridview. Please see my codes below.

    ASPX

        <asp:GridView ID="GridViewProjectsForChart" runat="server" AutoGenerateColumns="False" 
          DataKeyNames="ProjectID" DataSourceID="SqlDataSourceProjectsForChart" 
          EnableModelValidation="True" ShowHeader="False">
          <Columns>
            <asp:TemplateField >
              <ItemTemplate>
                <asp:Label ID="LabelProjectID" runat="server" Text='<%# Bind("ProjectID") %>' CssClass="hidepanel"></asp:Label>
                  <rsweb:ReportViewer ID="ReportViewerReportProjectSummaryChartByCash" runat="server" ProcessingMode="Remote" 
                  ShowCredentialPrompts="False" ShowDocumentMapButton="False" ShowFindControls="False"
                  ShowPageNavigationControls="False" ShowParameterPrompts="False" ShowPromptAreaButton="False"
                  ShowToolBar="False" ShowZoomControl="False" Visible="false" 
                  SizeToReportContent="True" ZoomMode="FullPage"  AsyncRendering="False">
                  <ServerReport
                     DisplayName="MyReport" ReportPath="/karadumanco/reports/ReportProjectSummaryChartByCash"
                        ReportServerUrl="https://rs2k801.discountasp.net/ReportServer" />
                  </rsweb:ReportViewer>
              </ItemTemplate>
            </asp:TemplateField>
          </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSourceProjectsForChart" runat="server" 
          ConnectionString="<%$ ConnectionStrings:MERCURYConnectionString %>" 
          SelectCommand="SELECT  ProjectID
              FROM Table1_Project
              WHERE (ContractCurrency IS NOT NULL) AND (ContractAmount IS NOT NULL)
              ORDER BY ProjectName ASC">
        </asp:SqlDataSource>

     

    VBA

    Imports System.Net
    Imports System.Security.Principal
    Imports Microsoft.Reporting.WebForms
    Imports Microsoft.ReportingServices
    
    Partial Class po_trackerSummaryChart
      Inherits System.Web.UI.Page
    
    
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
      End Sub
    
      Protected Sub GridViewProjectsForChart_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewProjectsForChart.RowDataBound
        Dim ReportViewerReportProjectSummaryChartByCash As ReportViewer = DirectCast(e.Row.FindControl("ReportViewerReportProjectSummaryChartByCash"), ReportViewer)
        Dim LabelProjectID As Label = DirectCast(e.Row.FindControl("LabelProjectID"), Label)
        If ReportViewerReportProjectSummaryChartByCash IsNot Nothing Then
          ReportViewerReportProjectSummaryChartByCash.Visible = True
          ReportViewerReportProjectSummaryChartByCash.Reset()
          ReportViewerReportProjectSummaryChartByCash.ServerReport.ReportPath = "/karadumanco/reports/ReportProjectSummaryChartByCash"
          ReportViewerReportProjectSummaryChartByCash.ServerReport.ReportServerUrl = New System.Uri("https://rs2k801.discountasp.net/ReportServer")
          ReportViewerReportProjectSummaryChartByCash.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
    
          Dim myparamProjectID As ReportParameter
          Dim myparamsProjectID As New List(Of ReportParameter)
          myparamProjectID = New ReportParameter("ProjectID", LabelProjectID.Text)
          myparamsProjectID.Add(myparamProjectID)
    
          ReportViewerReportProjectSummaryChartByCash.ServerReport.SetParameters(myparamsProjectID)
    
          ReportViewerReportProjectSummaryChartByCash.ServerReport.Refresh()
        End If
    
      End Sub
    End Class
    <Serializable()> _
    Public NotInheritable Class MyReportServerCredentials
      Implements IReportServerCredentials
    
    
      Public ReadOnly Property ImpersonationUser() As WindowsIdentity _
      Implements IReportServerCredentials.ImpersonationUser
        Get
          'Use the default windows user. Credentials will be
          'provided by the NetworkCredentials property.
          Return Nothing
    
    
        End Get
      End Property
    
    
      Public ReadOnly Property NetworkCredentials() As ICredentials _
      Implements IReportServerCredentials.NetworkCredentials
        Get
    
    
          Return New NetworkCredential("xxx", "xxx", "xxx")
    
    
        End Get
      End Property
    
    
      Public Function GetFormsCredentials(ByRef authCookie As Cookie, ByRef userName As String, ByRef password As String, ByRef authority As String) As Boolean _
      Implements IReportServerCredentials.GetFormsCredentials
    
    
        authCookie = Nothing
        userName = Nothing
        password = Nothing
        authority = Nothing
    
    
        'Not using form credentials
        Return False
      End Function
    
    
    End Class
    

     

    Sunday, February 20, 2011 12:05 PM

Answers

  • User-1312722619 posted

    I noticed that row credentials should be assigned on rowCreated event. Then i used RowDataBound event to assign parameters. So i split my codes as below. Issue resolved.

      Protected Sub GridViewProjectsForChart_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewProjectsForChart.RowCreated
        Dim ReportViewerReportProjectSummaryChartByCash As ReportViewer = DirectCast(e.Row.FindControl("ReportViewerReportProjectSummaryChartByCash"), ReportViewer)
        If ReportViewerReportProjectSummaryChartByCash IsNot Nothing Then
          ReportViewerReportProjectSummaryChartByCash.Visible = True
          ReportViewerReportProjectSummaryChartByCash.Reset()
          ReportViewerReportProjectSummaryChartByCash.ServerReport.ReportPath = "/karadumanco/reports/ReportProjectSummaryChartByCash"
          ReportViewerReportProjectSummaryChartByCash.ServerReport.ReportServerUrl = New System.Uri("https://rs2k801.discountasp.net/ReportServer")
          ReportViewerReportProjectSummaryChartByCash.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
        End If
      End Sub
    
      Protected Sub GridViewProjectsForChart_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewProjectsForChart.RowDataBound
        Dim ReportViewerReportProjectSummaryChartByCash As ReportViewer = DirectCast(e.Row.FindControl("ReportViewerReportProjectSummaryChartByCash"), ReportViewer)
        Dim LabelProjectID As Label = DirectCast(e.Row.FindControl("LabelProjectID"), Label)
        If ReportViewerReportProjectSummaryChartByCash IsNot Nothing Then
          Dim myparamProjectID As ReportParameter
          Dim myparamsProjectID As New List(Of ReportParameter)
          myparamProjectID = New ReportParameter("ProjectID", LabelProjectID.Text)
          myparamsProjectID.Add(myparamProjectID)
          ReportViewerReportProjectSummaryChartByCash.ServerReport.SetParameters(myparamsProjectID)
          ReportViewerReportProjectSummaryChartByCash.ServerReport.Refresh()
        End If
      End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 21, 2011 2:12 AM

All replies

  • User-37275327 posted

    try assign parameters, datasouce on gridview rawdatabound event. Rawdatabound is where report viewer is created.

    Monday, February 21, 2011 12:12 AM
  • User-37275327 posted

    try assign parameters, datasouce on gridview rawdatabound event. Rawdatabound is where report viewer is created.

    Monday, February 21, 2011 12:13 AM
  • User-1312722619 posted

    I noticed that row credentials should be assigned on rowCreated event. Then i used RowDataBound event to assign parameters. So i split my codes as below. Issue resolved.

      Protected Sub GridViewProjectsForChart_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewProjectsForChart.RowCreated
        Dim ReportViewerReportProjectSummaryChartByCash As ReportViewer = DirectCast(e.Row.FindControl("ReportViewerReportProjectSummaryChartByCash"), ReportViewer)
        If ReportViewerReportProjectSummaryChartByCash IsNot Nothing Then
          ReportViewerReportProjectSummaryChartByCash.Visible = True
          ReportViewerReportProjectSummaryChartByCash.Reset()
          ReportViewerReportProjectSummaryChartByCash.ServerReport.ReportPath = "/karadumanco/reports/ReportProjectSummaryChartByCash"
          ReportViewerReportProjectSummaryChartByCash.ServerReport.ReportServerUrl = New System.Uri("https://rs2k801.discountasp.net/ReportServer")
          ReportViewerReportProjectSummaryChartByCash.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
        End If
      End Sub
    
      Protected Sub GridViewProjectsForChart_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewProjectsForChart.RowDataBound
        Dim ReportViewerReportProjectSummaryChartByCash As ReportViewer = DirectCast(e.Row.FindControl("ReportViewerReportProjectSummaryChartByCash"), ReportViewer)
        Dim LabelProjectID As Label = DirectCast(e.Row.FindControl("LabelProjectID"), Label)
        If ReportViewerReportProjectSummaryChartByCash IsNot Nothing Then
          Dim myparamProjectID As ReportParameter
          Dim myparamsProjectID As New List(Of ReportParameter)
          myparamProjectID = New ReportParameter("ProjectID", LabelProjectID.Text)
          myparamsProjectID.Add(myparamProjectID)
          ReportViewerReportProjectSummaryChartByCash.ServerReport.SetParameters(myparamsProjectID)
          ReportViewerReportProjectSummaryChartByCash.ServerReport.Refresh()
        End If
      End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 21, 2011 2:12 AM
  • User1471008070 posted

    Thanks for your feedback. I am happy that you could solve your issue yourself. I mark it as answer, then other members will know the issue when encounter the same question.

    Friday, February 25, 2011 6:08 AM