views:

2698

answers:

3

I am pretty new in C# and my English is not so good - sorry in advance if I miss a point.

I tried to build an ASP.NET web site with a ReportService control. As you might already know, SSRS 2008 does not allow anonymous login. So, I tried to pass Credentials to SSRS which will be stored inside my web page so that users will be able to see the report without logging in.

I found the code below and put it on my WebForm, but I'm having a problem with the report parameters. If there are default values for the report parameters, the below code works okay. But, if I try to change the value of a parameter, the whole page is refreshed and before I click the "View Report" button, all parameters are reset to default or null values.

Any suggestion on how to avoid refreshing the whole page, or another way to pass the login info to SSRS? Thanks a lot in advance.

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using Microsoft.Reporting.WebForms;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ReportViewer1.Width = 800;
        ReportViewer1.Height = 600;
        ReportViewer1.ProcessingMode = ProcessingMode.Remote;
        IReportServerCredentials irsc =new CustomReportCredentials("administrator", "MYpassworw", "domena");
        ReportViewer1.ServerReport.ReportServerCredentials = irsc;
        ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.0.1/ReportServer/");
        ReportViewer1.ServerReport.ReportPath = "/autonarudzba/listanarudzbi";
        ReportViewer1.ServerReport.Refresh();
    }
}

public class CustomReportCredentials : IReportServerCredentials
{
     private string _UserName;
     private string _PassWord;
     private string _DomainName;

     public CustomReportCredentials(string UserName, string PassWord, string DomainName)
     {
        _UserName = UserName;
        _PassWord = PassWord;
        _DomainName = DomainName;
     }

     public System.Security.Principal.WindowsIdentity ImpersonationUser
     { 
        get { return null; } 
     } 

     public ICredentials NetworkCredentials
     {
        get { return new NetworkCredential(_UserName, _PassWord, _DomainName); }
     }

     public bool GetFormsCredentials(out Cookie authCookie, out string user,
      out string password, out string authority)
     {
        authCookie = null;
        user = password = authority = null;
        return false;
     }
}
+2  A: 

I really haven't messed with SSRS - but my ASP.NET hat tells me you may want to wrap that stuff in an if (!IsPostBack) block to keep it from running on the page refresh. My guess is that ReportViewer1.ServerReport.Refresh() pulls the default values again.

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack) 
    {
        ReportViewer1.Width = 800;
        ReportViewer1.Height = 600;
        ReportViewer1.ProcessingMode = ProcessingMode.Remote;
        IReportServerCredentials irsc =new CustomReportCredentials("administrator", "MYpassworw", "domena");
        ReportViewer1.ServerReport.ReportServerCredentials = irsc;
        ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.0.1/ReportServer/");
        ReportViewer1.ServerReport.ReportPath = "/autonarudzba/listanarudzbi";
        ReportViewer1.ServerReport.Refresh();
    }
}
Mark Brackett
I try to cut out line ReportViewer1.ServerReport.Refresh() but unfortunately same thing happened again.
adopilot
Did you wrap it in a IsPostBack check?
Mark Brackett
A: 

Sorry on my Late answer Yes it helps me but I also did the thing on some other way.

I made new function in code and in design view on properties in events for reportViewer object In selection INIT i picked up my function. After that the page works normally and I can change values for parameters.

Default.aspx now looks like

    </head>
      <body>
        <form id="form1" runat="server">
         <div>
            <rsweb:ReportViewer ID="ReportViewer1" runat="server" onload="Admir">
            </rsweb:ReportViewer>
         </div>
       </form>
    </body>

And Default.aspx.cs looks like this

 public void Admir(object sender, EventArgs e)
    {
        ReportViewer1.Width = 800;
        ReportViewer1.Height = 600;
        ReportViewer1.ProcessingMode = ProcessingMode.Remote;
        IReportServerCredentials irsc = new CustomReportCredentials("administrator", "mypass", "domena");
        ReportViewer1.ServerReport.ReportServerCredentials = irsc;
        ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.0.1/ReportServer/");
        ReportViewer1.ServerReport.ReportPath = "/autonarudzba/listanarudzbi";
        ReportViewer1.ServerReport.Refresh();

    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
adopilot
A: 

we got our problem solved from your problem. Thanks a lot.

I am so glad to even and I can someone help on this site
adopilot