How to pass credentials when accessing SSRS report through URL - asp.net

I am trying to access a SSRS report using URL like below
http://MyServerIP/ReportServer?/FolderName/ReportName&Param1=ParamValue&rs:Command=Render&rs:Format=HTML4.0&rc:Toolbar=false
When I try to access above Url, I am asked for my network credentials, giving which I get all pages of SSRS report rendered in browser window.
Now I want to display these contents in a popup window inside my webApp. For this I tried to make a jquery request and get contents, but doing this I get 401 unauthorized error. So I wanna know if there is a way to send credentials in jquery ajax get request.
As a turnaround I tried using below C# code to retrieve data, but it didn't helped either and gave same 401 error
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("username", "password", "domain");
divContents.InnerText = client.DownloadString(my report path);
I am using SSRS 2008 R2 and my requirement is to show all pages of report in popup window. So all pointers in this direction are welcome.
Adding a point at last, my web app and report may or may not reside on same domain.
Thanks,
Ravi

What I would try:
Create a new page. On the C# side, use the ReportExecution2005 web service to render your report to HTML. Then pump the result out to the window.
In your pop-up, either call the new C# page via Ajax (to get the HTML) and inject the output into your jQuery window, or pop up the page itself as a separate browser window.
I can provide some sample code if you need it.
ETA: I found a possibly valuable piece of information:
This is from the HTML Device Settings page (emphasis mine):
Toolbar
Indicates whether to show or hide the toolbar. The default of this
parameter is true. If the value of this parameter is false, all
remaining options (except the document map) are ignored. If you omit
this parameter, the toolbar is automatically displayed for rendering
formats that support it.
The Report Viewer toolbar is rendered when you use URL access to
render a report. The toolbar is not rendered through the SOAP API.
However, the Toolbar device information setting affects the way that
the report is displayed when using the SOAP Render method. If the
value of this parameter is true when using SOAP to render to HTML,
only the first section of the report is rendered. If the value is
false, the entire HTML report is rendered as a single HTML page.

You pass the credentials like this in the query string:
dsu:DataSourceName=userName&dsp:DataSourceName=password
Replace the elements in bold with the values from your report, for example:
http://MyServerIP/ReportServer?/FolderName/ReportName&Param1=ParamValue&rs:Command=Render&rs:Format=HTML4.0&rc:Toolbar=false&dsu:Data=reportreader&dsp:Data=password1

You can use the Report Viewer control if you want to allow public access to secure reports without asking for credentials.
Create a new .aspx page and use the ReportViewer control like so:
<rsweb:ReportViewer ID="MainReportViewer" runat="server" BackColor="White"
Font-Names="Verdana" Font-Size="8pt" InteractiveDeviceInfos=" (Collection)"
ProcessingMode="Remote" ShowBackButton="False" ShowFindControls="False"
ShowPageNavigationControls="False" SizeToReportContent="True"
ToolBarItemBorderColor="White" ToolBarItemHoverBackColor="White"
WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="100%">
<ServerReport ReportServerUrl="" />
</rsweb:ReportViewer>
The code below can be used in the codebehind of your .aspx page to configure the report server, username and password, [etc..] in your Report Viewer
protected void Page_Init(Object sender, EventArgs e)
{
string UserName = ConfigurationManager.AppSettings["SsrsUserName"];
string Password = ConfigurationManager.AppSettings["SsrsPassword"];
string Domain = ConfigurationManager.AppSettings["SsrsDomain"];
string ReportServerRoot = ConfigurationManager.AppSettings["SsrsServerRoot"];
string ReportServerPath = ConfigurationManager.AppSettings["SsrsReportServerPath"];
MainReportViewer.ProcessingMode = ProcessingMode.Remote;
IReportServerCredentials irsc = new CustomReportCredentials(UserName, Password, Domain);
MainReportViewer.ServerReport.ReportServerCredentials = irsc;
MainReportViewer.ServerReport.ReportServerUrl = new Uri(ReportServerRoot);
MainReportViewer.ServerReport.ReportPath = ReportServerPath + "YourReportFileName";
}

Related

AjaxFileUpload control doesnt work when page have querystring in asp.net

I have a button on a .aspx page which opens the popup to upload images of selected item.
ListEdit.aspx
<asp:Button ID="btnListingImageUpload" runat="server" Text="Upload Images"
OnClientClick="basicPopup()"/>
Javascript:
function basicPopup() {
var QuoteId = document.getElementById('<%= hdnQuoteIDForListing.ClientID%>').value;
var IsPrep = document.getElementById('<%= hdnIsPrep.ClientID%>').value;
alert(IsPrep);
popupWindow = window.showModalDialog('ListingImageUpload.aspx?QuoteID=' + QuoteId + '&IsPrep=' + IsPrep, 'popUpWindow', 'height=400,width=600,left=200,top=250,resizable=0');
return false;
}
AjaxFileUpload Control on Popup Page:
<cc1:AjaxFileUpload ID="AjaxFileUpload2" ThrobberID="myThrobber" ContextKeys="fred" AllowedFileTypes="jpg,jpeg" MaximumNumberOfFiles="10" runat="server" OnUploadComplete="AjaxFileUpload1_UploadComplete1"
OnClientUploadComplete="onClientUploadCompleteFront" />
When i click on button it opens the page as popup containing AJAXFileUpload control and querystring in popup page. When i click on 'Upload' button of popup page containing AjaxFileUpload control it gives following error:
JavaScript runtime error: Sys.ArgumentException: Cannot deserialize. The data does not correspond to valid JSON.
Parameter name: data
But, when is use session instead of querystring it works fine!
I have googled and found this link but i am not able to resolve it. I have AJAXControlToolKit.dll (only)in bin folder and not the source files and other binaries.
NOTE: Please suggest solution using querystring only. Reason is, multiple instances of this popup will open at time. So, cant use Session variables.
Help Appreciated!
You can decompile de .dll with some App like Telerik, and then apply changes on the code and recompile.
This is a known issue, when AjaxFileUpload post back it takes your page URL and appends onto the end of it it's own.query strings (contextkey and guid). This works fine if your page URL doesn't already contain any query strings but
if it does then you end up with a URL that contains two question marks which will corrupt your final query string value and this in turn stops the upload from working.
Check this Known Issue

asp:HyperLink not pass by querystring

I am using a asp:HyperLink as it gave me the ability to open up the linked page in a new tab.
One issue I am facing with this control is that as the info I need to pass is confidential, I do not want to do something like:
<asp:HyperLink ID="LinkButton2" runat="server" Target="_blank" NavigateUrl= '<%# String.Format("SPage.aspx?val={0}", Eval("Uid")) %>'>View/Print</asp:HyperLink>
In other words, I do not want to pass info such that it is viewable by the user. Is there any other way around this. Is there any other control that can easily open up the link on another page and yet give me the ability to pass info without querystring (as this will be viewable). My main concern is that I am passing CONFIDENTIAL info in the querystring and as such do not want to user to view it.
What you can do :
From the server side :
LinkButton2.NavigateUrl="~/SPage.aspx?uid=" +Uri.EscapeDataString(Utils.Encrypt(Uid)); //Utils.encrypt is your encryption function
Users will see it , but they won't understand nothing from it.
Later , on your page :
var myValue = Utils.Descrypt(Uri.UnescapeDataString(request["uid"]));

Winform browser control "attachment" button

We have a winform app that has a browser control on it. Previously these files (always very small 10kb etc.) were stored at a unc location. We would generate some html and load the html into the browser. If we wanted to make one of these small files available we would include in the HTML an anchor tag () WHen the html was displayed in the browser control so would be the link. The user could click on the link and the file save as dialog would appear.
We are now storing these files in the db as varbinary and thus there is no longer a physical location for the anchor tag to point to. I have several thoughts but would like the members of SO who are way smarter than me to chime in.
Option 1 in my mind would be to have an image button, anchor tag, something in the html to click on. I would handle the "onclick" either in javascript or as a postback. This seems doable for my level of knowledge EXCEPT I do not know how to get the byte[] to translate into the save as dialog for the user....do I render it to disk first?
The other idea I had was to have a button that is NOT in the browser control. This button would be hidden / visible if the biz rules said to show a file. Clicking on the button would then generate the byte[] which is easily turned into a file and the save as shown dialog shown in the winform app.
So any thought or all together different suggestions welcome
TIA
JB
I understand that you are in control of the ASP.NET web page shown in the windows forms web browser control so you can edit that page and build it the way you want.
if that is true, behavior in hosted web browser or in normal IE session is the same and I would suggest to create a bunch of hyper links or buttons in the asp.net web form page each one which a specific ID, like the ID of the file to download. then you can create an handler or a button_click event handler where you get the byte[] of the file by the clicked button/link associated file Id, or from query string if you initiated an handler call, and then you start streaming down to the browser the file content, the browser will do all what is required for you.
for example, just as a starting point, a bit of code taken from here: http://social.msdn.microsoft.com/Forums/en-US/silverlightnet/thread/d6a5087f-43b1-4782-95f1-d1376130d2c8
shows you a possible way to do this from a page load, the trick is that the call to GetDocument gets the proper file content for you (in this case from the query string, imagine like if we are inside an handler processing method) and returns a class DocumentInfo which contains the bytes. you do nor need this DocumentInfo, you can just have a method which returns byte[] by File Id for example...
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string queryString = this.Request.QueryString.ToString();
if (string.IsNullOrEmpty(queryString)) return;
DocumentInfo documentInfo = GetDocument(queryString);
if (!documentInfo.HasValue) return;
Response.ClearHeaders();
Response.ClearContent();
Response.AppendHeader("Content-Length", documentInfo.Value.Content.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=Test.doc");
Response.BinaryWrite(documentInfo.Value.Content);
Response.End();
}
}

SSRS - Link not clickable in .net Report Application

I have a report that specifies a 'Go to URL' action for a textbox. The URL I am using is simply a field from the dataset, so the expression for the URL is something like "=Fields!URLLinkText.Value". When I deploy the report to SSRS Report Manager, the link works fine. It is clickable and opens the URL. However, when I link to the report from the custom asp.Net Reporting Application, the link is not clickable. The cursor of the mouse does not even change when I hover over the link. It seems like the hyperlink/Go To property of the textbox is completely removed. At first, I thought that this had to be an issue with the configuration of the reporting app, which was disabling external hyperlinks. However, I created another report with just one textbox with a Go To Action to go to www.CNN.com and it worked on both the Report Manager and the Report Application...
Any suggestions?
I was just posting about a possibly related issue. It does not involve any custom reporting app though. http://weblogs.asp.net/mnissen/archive/2009/03/26/reporting-services-does-not-display-hyperlink-for-placeholder-with-go-to-url-action.aspx
A few different options you can try: wrap the link in javascript, try "servername:port" instead of the site name if its internal, or try reversing the slashes like http backslash backslash...
You will need to handle the Hyperlink clicked event for your reportviewer control:
Assign the handler in your reportviewer constructor
YourReportViewerControl.Hyperlink += new HyperlinkEventHandler(YourReportViewerControl_Hyperlink);
void YourReportViewerControl_Hyperlink(object sender, HyperlinkEventArgs e)
{
e.Cancel = true;
System.Diagnostics.Process.Start(e.Hyperlink);
}

'Go to Report' (drillthrough) action not working in SSRS and ASP.NET

I've recently started working with SSRS 2008 and ASP.Net.
I must develop a report with 3 different levels of detail. So, I decided the best solution was to develop 3 different reports and provide some drill-through mechanism in order to allow navigation. For that, I set the 'Action' property of one of the textboxes to 'Go to report' and set the correct url.
The parameters passed to the report need to be validated first. So, for a matter of flexibility and better user experience I let the user enter the parameters using standard ASP.Net controls. When the user clics on my custom button 'Show report' the following code executes:
ReportViewer2.ServerReport.ReportPath = ".. my report path ..";
ReportViewer2.ServerReport.ReportServerUrl = new Uri(".. my report url ..");
ReportParameter p1 = new ReportParameter("dateStart", dateStart.ToString());
ReportParameter p2 = new ReportParameter("dateEnd", dateEnd.ToString());
ReportViewer2.ServerReport.SetParameters(p1);
ReportViewer2.ServerReport.SetParameters(p2);
ReportViewer2.ServerReport.Refresh();
Then the report is shown, but the links for navigating to the other reports don't work.
You may notice that the parameters added are visible, thus letting me press the 'View Report' button wich is embedded inside the report viewer. If I do so, the report is rendered again and then everithing is Ok. It's like the ReportViewer.ServerReport.Refresh() method is missing something.
That's a problem, because the requirements states that the parameteres need to be hidden.
When I execute the report from inside VS or the Report Server the links work ok, but in those cases I always must press the standard 'View Report' button.
Is this a bug of the ReportViewer control or am I missing something here?
Thanks in advance.
Regards,
Gonzalo.
The report viewer contains an update panel. You must call the Update method of the update panel in the pre-render event of the report viewer:
protected void ReportViewer2_PreRender(object sender, EventArgs e)
{
((UpdatePanel)this.ReportViewer2.Controls[1]).Update();
}

Resources