I have developed a web app that uses forms authentication. I wrote it in
asp.net 2.0. My server is running windows 2003 server standard and IIS. I
have also installed on the same machine SQL Server 2005 with Reporting
Services.
From my webapplication, I have a button that the user can click and then I
have the Report Viewer control generate a report. However, I do not know how
to pass the proper credentials to the report server. I would like to pass
one username and password that has permissions to run that report. My code
is follows:
Private Sub saveRptAs(ByVal s_rptType As String)
Dim warnings As Microsoft.Reporting.WebForms.Warning()
Dim streamids As String()
Dim mimeType As String
Dim encoding As String
Dim extension As String
ReportViewer1.ServerReport.ReportServerUrl = New
Uri("http://myserver/reportserver")
ReportViewer1.ServerReport.ReportPath = "/reports/Individual Report"
Dim test As New NetworkCredential("localuser", "password", "domain")
ReportViewer1.ServerReport.ReportServerCredentials = test
Dim rprameter As ReportParameter = New ReportParameter("user_no",
Profile.DTGVariables.SelectedYMNo)
Me.ReportViewer1.ServerReport.SetParameters(New ReportParameter()
{rprameter})
Dim bytes As Byte() = ReportViewer1.ServerReport.Render(s_rptType,
Nothing, mimeType, encoding, extension, streamids, warnings)
Response.Buffer = True
Response.Clear()
Response.ContentType = mimeType
Response.AddHeader("content-disposition", "attachment;
filename=sample." + extension)
Response.BinaryWrite(bytes)
Response.Flush()
Response.End()
End Sub
When I click on the button I get the following message:
Unable to cast object of type 'System.Net.NetworkCredential' to type
'Microsoft.Reporting.WebForms.IReportServerCredentials'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of
type 'System.Net.NetworkCredential' to type
'Microsoft.Reporting.WebForms.IReportServerCredentials'.
Can someone help me with the credentials issue? Do I need to change
Reporting Services to use Forms Authentication?
Your help and insight is greatly appreciated.
Thanks
Nate DoggYou have to create a class that inherits from IReportServerCredentials
interface.
read this post:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=157916&SiteID=1
"Nate Dogg" wrote:
> I have developed a web app that uses forms authentication. I wrote it in
> asp.net 2.0. My server is running windows 2003 server standard and IIS. I
> have also installed on the same machine SQL Server 2005 with Reporting
> Services.
> From my webapplication, I have a button that the user can click and then I
> have the Report Viewer control generate a report. However, I do not know how
> to pass the proper credentials to the report server. I would like to pass
> one username and password that has permissions to run that report. My code
> is follows:
> Private Sub saveRptAs(ByVal s_rptType As String)
> Dim warnings As Microsoft.Reporting.WebForms.Warning()
> Dim streamids As String()
> Dim mimeType As String
> Dim encoding As String
> Dim extension As String
> ReportViewer1.ServerReport.ReportServerUrl = New
> Uri("http://myserver/reportserver")
> ReportViewer1.ServerReport.ReportPath = "/reports/Individual Report"
>
> Dim test As New NetworkCredential("localuser", "password", "domain")
> ReportViewer1.ServerReport.ReportServerCredentials = test
> Dim rprameter As ReportParameter = New ReportParameter("user_no",
> Profile.DTGVariables.SelectedYMNo)
> Me.ReportViewer1.ServerReport.SetParameters(New ReportParameter()
> {rprameter})
> Dim bytes As Byte() = ReportViewer1.ServerReport.Render(s_rptType,
> Nothing, mimeType, encoding, extension, streamids, warnings)
> Response.Buffer = True
> Response.Clear()
> Response.ContentType = mimeType
> Response.AddHeader("content-disposition", "attachment;
> filename=sample." + extension)
> Response.BinaryWrite(bytes)
> Response.Flush()
> Response.End()
> End Sub
> When I click on the button I get the following message:
> Unable to cast object of type 'System.Net.NetworkCredential' to type
> 'Microsoft.Reporting.WebForms.IReportServerCredentials'.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information about
> the error and where it originated in the code.
> Exception Details: System.InvalidCastException: Unable to cast object of
> type 'System.Net.NetworkCredential' to type
> 'Microsoft.Reporting.WebForms.IReportServerCredentials'.
>
> Can someone help me with the credentials issue? Do I need to change
> Reporting Services to use Forms Authentication?
> Your help and insight is greatly appreciated.
> Thanks
> Nate Dogg
>
No comments:
Post a Comment