Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 907
  • Last Modified:

Sql Server Report on Asp.net

Hi,

When I am trying to show Reports on .Aspx page form Virtual Directory it is showing this error "The permissions granted to user 'NT AUTHORITY\NETWORK SERVICE' are insufficient for performing this operation. (rsAccessDenied)" . I have used ReportViewer control and VS 2008,  it is working fine at local host.

Thank you.
0
mismail75
Asked:
mismail75
1 Solution
 
TSmoothCommented:
You will need to setup proper credentials for your asp.net site to access the reporting server. Is the SQL Server reporting server on the same machine as the asp.net web server where your page will be hosted? If not, you will need your report viewer control to essentially "log in" to the report server on an account that is granted permission to access reports through SQL Server report server's configuration.

Here's a sample of how you can specify separate credentials for your reports.

Add a new class to your asp.net and set it up lik the code below. Then in your web.config, you will need to add the following properties to your <appSettings> section, replacing with appropriate values:

<add key="MyReportViewerUser" value="MyUser"/>
    <add key="MyReportViewerPassword" value="MyUserPassword"/>
    <add key="MyReportViewerDomain" value="MyUserDomain"/>

Finally, on the page that contains your report viewer control, do the following in something like the load event of the page:
ReportViewer1.ServerReport.ReportPath = "yourReportPath"
ReportViewer1.ServerReport.ReportServerUrl = "yourReportServerUrl"
ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials()

Hopefully this gets you on the right track.

' --------------- Class to add to ASP.NET Project
Imports System.Security.Principal
Imports Microsoft.Reporting.WebForms
Imports System.Net
 
<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
 
            'Read the user information from the web.config file.  
            'By reading the information on demand instead of storing 
            'it, the credentials will not be stored in session, 
            'reducing the vulnerable surface area to the web.config 
            'file, which can be secured with an ACL.
 
            'User name
            Dim userName As String = _
                ConfigurationManager.AppSettings("MyReportViewerUser")
 
            If (String.IsNullOrEmpty(userName)) Then
                Throw New Exception("Missing user name from web.config file")
            End If
 
            'Password
            Dim password As String = _
                ConfigurationManager.AppSettings("MyReportViewerPassword")
 
            If (String.IsNullOrEmpty(password)) Then
                Throw New Exception("Missing password from web.config file")
            End If
 
            'Domain
            Dim domain As String = _
                ConfigurationManager.AppSettings("MyReportViewerDomain")
 
            If (String.IsNullOrEmpty(domain)) Then
                Throw New Exception("Missing domain from web.config file")
            End If
 
            Return New NetworkCredential(userName, password, domain)
 
        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

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now