asp.net - pass authentication header to image requests in iframe -
i sure title of question doesn't makes sense, couldn't think better now.
problem: main task show all pages of ssrs report in popup inside 1 of pages of asp.net mvc application.
to achieve used below approach:
- add jquery popup in mypage.cshtml(i need report contents inside popup)
- when popup opens(on client action), make jquery ajax request second page proxypage.aspx
on proxy page make webrequest reportserver network credentials , report html
webrequest request = webrequest.create( "http://myreportserver/reportserver?/ myreportname&rs:command=render&rs:format =html4.0&rc:toolbar=false¶m1=blabla123"); request.credentials = new networkcredential(myusername, mypassword); httpwebresponse response = (httpwebresponse)request.getresponse(); stream receivestream = response.getresponsestream(); streamreader readstream = new streamreader(receivestream, system.text.encoding.utf8); string str = readstream.readtoend(); response.write(str);
html proxypage write in div inside popup or using iframe show full proxy page inside it.
till here things go , thereafter yet problem writing question
when report's html gets rendered in popup makes request report server retrieve images embedded in report.
since these requests report server doesn't send network credentials did in step 3, prompt entering credentials.
i need approach through these image request may somehow authenticated credentials have supplied earlier.
ssrs stream resources in location specify.
private byte[] internalrenderreport(report report, list<reportparameter> parameters, string format, int pagenumber, ref int totalpages, string virtualtempfolder, string physicaltempfolder) { checkconnection(); byte[] result = null; reportexecution2005.reportexecutionservice _execservice=new reportexecution2005.reportexecutionservice(); sys = _systemservice.getcurrentsystem(); _execservice.url = sys.reportingservices.servicerooturl+"/reportexecution2005.asmx"; networkcredential credentials = new networkcredential(sys.reportingservices.credentials.username, sys.reportingservices.credentials.password, sys.reportingservices.credentials.domain); _execservice.credentials=credentials; reportexecution2005.parametervalue[] rsparams = null; if (parameters != null) { rsparams = new reportexecution2005.parametervalue[parameters.count]; int x = 0; foreach (reportparameter p in parameters) { rsparams[x] = new reportexecution2005.parametervalue(); rsparams[x].name = p.parametername; rsparams[x].value = p.selectedvalue; x++; } } stringbuilder devinfo = new stringbuilder(); if (format.toupper().startswith("html")) { devinfo.append("<deviceinfo>"); devinfo.append("<htmlfragment>true</htmlfragment>"); devinfo.append("<section>" + pagenumber.tostring() +"</section>"); devinfo.append("<streamroot>" + virtualtempfolder + "</streamroot>"); /*devinfo.append("<zoom>200</zoom>");*/ devinfo.append("</deviceinfo>"); } else devinfo.append("<deviceinfo><toolbar>false</toolbar></deviceinfo>"); string extension; string mimetype; string encoding; string[] streamids = null; reportexecution2005.warning[] warnings = null; reportexecution2005.executionheader execheader = new reportexecution2005.executionheader(); reportexecution2005.executioninfo rpt = _execservice.loadreport(report.reportpath, null); if(rsparams!=null) _execservice.setexecutionparameters(rsparams, "en-us"); _execservice.executionheadervalue = execheader; _execservice.executionheadervalue.executionid = rpt.executionid; //result = _execservice.render2(format, devinfo, reportexecution2005.pagecountmode.actual, out extension, out mimetype, out encoding, out warnings, streamids); result = _execservice.render(format, devinfo.tostring(), out extension, out mimetype, out encoding, out warnings, out streamids); if (format.toupper().startswith("html")) { // each image stream returned call render, // render stream , save application root string filepath = physicaltempfolder; byte[] image; // each image stream returned call render, // render stream , save application root foreach (string streamid in streamids) { image = _execservice.renderstream("html4.0", streamid, null, out encoding, out mimetype); filestream stream = file.openwrite(filepath + streamid); stream.write(image, 0, image.length); stream.close(); } } rpt = _execservice.getexecutioninfo(); totalpages = rpt.numpages; return result; }
this return either raw html or contents push file. added temp folder solution deployed server. can place web.config file in temp folder following contents allow extension less contents ssrs render when using streams:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webserver> <staticcontent> <mimemap fileextension=".*" mimetype="image/png" /> </staticcontent> <handlers> <clear /> <add name="staticfile" path="*" verb="*" type="" modules="staticfilemodule,defaultdocumentmodule,directorylistingmodule" scriptprocessor="" resourcetype="either" requireaccess="read" allowpathinfo="false" precondition="" responsebufferlimit="4194304" /> </handlers> </system.webserver> </configuration>
then use following functions physical , virtual temp folders:
physcicaltempfolder= appdomain.currentdomain.basedirectory + @"temp\"; virtualtempfolder=return url.content("~/temp/");
and clean after each day can add powershell command similar to:
remove-item d:\xxx\webapplications\externalreports\temp\* -exclude *.config
then add .bat calls ps script:
powershell -command "& 'c:\xxx\scripts\ssrscleantempfiles\ssrscleantempfiles.ps1'"
with can configure scheduled task on server call .bat file everyday , clean temp folder of application.