401 unautherized access asp.net and sql reporting services when accessing on remote server
If you are running SQL Server reporting services on remote server and your asp.net front end application is displaying reports inside a repot viewer control using remote report settings then you might get 401 unauthorized access error.
This error mostly comes when using Active Directory permission, to solve this issue you need to acess reports using active directory account not your local asp.net account. You should create a new class and implement IReportServerCredentials.
First on ASPX page load even you should set the report viewer controls report server credentials.
If Not Page.IsPostBack ThenReportViewer1.ServerReport.ReportServerCredentials =
New ReportCredentials() End IfHere is the code for ReportCredentials Class.
Imports
Microsoft.VisualBasicImports
Microsoft.Reporting.WebFormsImports
System.Security.PrincipalPublic
Class ReportCredentials Implements IReportServerCredentials Private _Username As String Private _Password As String Private _Domain As String Public Sub New() 'Sub New 1 'Only required if you want every one 'to access reports using same username password._Username =
"USERNAME"_Password =
"PASSWORD"_Domain =
"DOMAIN NAME" End Sub Public Sub New(ByVal Username As String, ByVal Password As String, ByVal Domain As String) 'Sub New 2, username password is provided 'every time new object of class is created._Username = Username
_Password = Password
_Domain = Domain
End Sub Public ReadOnly Property ImpersonationUser() As System.Security.Principal.WindowsIdentity Implements Microsoft.Reporting.WebForms.IReportServerCredentials.ImpersonationUser Get Return Nothing End Get End Property Public ReadOnly Property NetworkCredentials() As System.Net.ICredentials Implements Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentials Get 'uncomment the fist line if you want to use default netowrk credentials 'of each user, Also remove the Sub New 1. 'Return System.Net.CredentialCache.DefaultNetworkCredentials Return New Net.NetworkCredential(_Username, _Password, _Domain) End Get End Property Public Function GetFormsCredentials(ByRef authCookie As System.Net.Cookie, ByRef userName As String, ByRef password As String, ByRef authority As String) As Boolean Implements Microsoft.Reporting.WebForms.IReportServerCredentials.GetFormsCredentialsuserName = _Username
password = _Password
authority = _Domain
Return Nothing End FunctionEnd
Class