Using ReportViewer in ASP.net

Discussion in 'Databases' started by alvaradd, May 4, 2008.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hello, Can Someone help me? I don't know if I'm doing something wrong.
    I 'm doingsomereports using the Reporting ServicesandI want to show them in ASP.net (VB) using ReportViewer, for this I put my reports in my reportserver and I added Reportviewer nevertheless I obtained the following error:

    The request failed with HTTP status 401: Unauthorized

    I was trying to see what was the problem and I found information about credentials and as possible solution the following code:

    Imports System.Net</o:p>
    Imports System.Security.Principal</o:p>
    Imports Microsoft.Reporting.WebForms</o:p>
    </o:p>
    Partial Class Reports</o:p>
    Inherits System.Web.UI.Page</o:p>
    Protected Sub Page_Init(ByVal sender As Object, _</o:p>
    ByVal e As System.EventArgs) _</o:p>
    Handles Me.Init</o:p>
    </o:p>
    ReportViewer1.ServerReport.ReportServerCredentials = _</o:p>
    New MyReportServerCredentials()</o:p>
    </o:p>
    End Sub</o:p>
    </o:p>
    End Class</o:p>
    </o:p>
    <Serializable()> _</o:p>
    Public NotInheritable Class MyReportServerCredentials</o:p>
    Implements IReportServerCredentials</o:p>
    </o:p>
    Public ReadOnly Property ImpersonationUser() As WindowsIdentity _</o:p>
    Implements IReportServerCredentials.ImpersonationUser</o:p>
    Get</o:p>
    </o:p>
    'Use the default windows user. Credentials will be</o:p>
    'provided by the NetworkCredentials property.</o:p>
    Return Nothing</o:p>
    </o:p>
    End Get</o:p>
    End Property</o:p>
    </o:p>
    Public ReadOnly Property NetworkCredentials() As ICredentials _</o:p>
    Implements IReportServerCredentials.NetworkCredentials</o:p>
    Get</o:p>
    </o:p>
    'Read the user information from the web.config file. </o:p>
    'By reading the information on demand instead of storing </o:p>
    'it, the credentials will not be stored in session, </o:p>
    'reducing the vulnerable surface area to the web.config </o:p>
    'file, which can be secured with an ACL.</o:p>
    </o:p>
    'User name</o:p>
    Dim userName As String = _</o:p>
    ConfigurationManager.AppSettings("MyReportViewerUser")</o:p>
    </o:p>
    If (String.IsNullOrEmpty(userName)) Then</o:p>
    Throw New Exception("Missing user name from web.config file")</o:p>
    End If</o:p>
    </o:p>
    'Password</o:p>
    Dim password As String = _</o:p>
    ConfigurationManager.AppSettings("MyReportViewerPassword")</o:p>
    </o:p>
    If (String.IsNullOrEmpty(password)) Then</o:p>
    Throw New Exception("Missing password from web.config file")</o:p>
    End If</o:p>
    </o:p>
    'Domain</o:p>
    Dim domain As String = _</o:p>
    ConfigurationManager.AppSettings("MyReportViewerDomain")</o:p>
    </o:p>
    If (String.IsNullOrEmpty(domain)) Then</o:p>
    Throw New Exception("Missing domain from web.config file")</o:p>
    End If</o:p>
    </o:p>
    Return New NetworkCredential(userName, password, domain)</o:p>
    </o:p>
    End Get</o:p>
    End Property</o:p>
    </o:p>
    Public Function GetFormsCredentials(ByRef authCookie As Cookie, _</o:p>
    ByRef userName As String, _</o:p>
    ByRef password As String, _</o:p>
    ByRef authority As String) _</o:p>
    As Boolean _</o:p>
    Implements IReportServerCredentials.GetFormsCredentials</o:p>
    </o:p>
    authCookie = Nothing</o:p>
    userName = Nothing</o:p>
    password = Nothing</o:p>
    authority = Nothing</o:p>
    </o:p>
    'Not using form credentials</o:p>
    Return False</o:p>
    </o:p>
    End Function</o:p>
    </o:p>
    End Class
    Also I added the follow code in the web config:


    <appSettings>


    <add key="MyReportViewerUser" value="rs_user"/>


    <add key="MyReportViewerPassword" value="*****"/>


    <add key="MyReportViewerDomain" value=https://Server/ReportServer />


    </appSettings>
    But now I'm getting the next message:

    <LI style="DISPLAY: inline; FONT-WEIGHT: normal; FONT-SIZE: 8pt; FONT-FAMILY: Verdana">The attempt to connect to the report server failed. Check your connection information and that the report server is a compatible version.

      • <LI style="DISPLAY: inline; FONT-WEIGHT: normal; FONT-SIZE: 8pt; FONT-FAMILY: Verdana">The request failed with HTTP status 404: Not Found.
        <LI style="DISPLAY: inline; FONT-WEIGHT: normal; FONT-SIZE: 8pt; FONT-FAMILY: Verdana">
        <LI style="DISPLAY: inline; FONT-WEIGHT: normal; FONT-SIZE: 8pt; FONT-FAMILY: Verdana">








    Can Someone help me?


    Thanks
     
  2. wisemx sent me this information:


    This is something I'm going to make some videos for soon since there are so many requests. For now please look at this thread: http://forums.asp.net/t/1235370.aspx If that doesn't help let me know....

    I read the thread and I followed all the steps and It worked,
    Thanks wisemx
     
  3. Good job [​IMG]
    Salute,
    Mark
     
  4. This is something I'm going to make some videos for soon since there are so many requests.
    For now please look at this thread:
    http://forums.asp.net/t/1235370.aspx

    If that doesn't help let me know.
    Salute,
    Mark
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page