IronPDF: using ChromePdfRenderer.RenderUrlAsPdf - asp.net

I'm using the ChromePdfRenderer.RenderUrlAsPdf method to render a ASP.NET blazor page.
That page is using some internal methods from the model. When everything is good, it works fine.
The problem is that when any of those methods fails, the server returns an error page, with HTTP status code = 500 and IronPDF is generating the pdf with that error page in it. (Of course, that's what the url is returning)
My question: Is there a way of getting the HTTP status code that IronPDF is getting internally, so I can decide based on this, if the genrated PDF is valid or not?
Note: I know I could get the html from the url first, and then use the "RenderHtmlAsPdf" methods, but that's not the point.

Related

JMeter - viewing reports on .net application served from SSRS

I have an older aspx .net website I am testing and in some of the tests I want to view some reports. I am able to visit the report page and make selections but when I hit view report, it fails to view the report and I get a page redirect error.aspx.
Here is my test plan:
New Test Plan:
I created regular expression extractors for __VIEWSTATE and __EVENTVALIDATION that I also added the the post HTTP request to view the report. The parameters have all the report options and these on the bottom:
Is there anything I'm missing to be able to pull the reports? I believed they're served to the website using SSRS. I don't know if that makes a difference.
EDIT: I just noticed that it is losing the value for __VIEWSTATE and __EVENTVALIDATION in the request body even though I set the variable. The login and report option post http calls have a value for these parameters but then it disappears and defaults to ERROR for the view report post call.
Here are my regular expressions
EDIT: New CSS Extractors
Here's HTTP Requests
Where the issue is at
The error Response body:
Headers for the report options and report view POST HTTP requests
You're getting default values of ERROR because your regular expressions fail to extract the values from the response.
In general using regular expressions for parsing HTML isn't recommended, consider using CSS Selector Extractor instead, example configuration would be something like:
See CSS Selectors Reference for more information
I believe you should also correlate this __VIEWSTATEGENERATOR value

Javascript to handle a form return

I have a standard html registration page that targets an external .asp page on submit.
What happens is that currently the .asp (which I don't have access to)returns an entire html page.
Instead I would like to somehow parse the returned html and populate the existing form with either
a) validation errors if incorrect
or
B) some sort of success message if all validated
Can anyone tell me if this is possible and or help with some pseudo code?
This is doable in JavaScript using ajax, but it requires that the ASP page (presumably on a different domain) sends appropriate CORS HTTP headers. Even if you don't have access to the actual ASP page, you may be able to get someone to setup the headers in IIS on their server.
Otherwise, you're stuck moving everything server-side, i.e. simulating the POST on your own webserver, and scraping the HTML to get the status back. That looks something like:
Postback the page to your own page (or use Ajax)
On your server, initiate a web request post of the data to the ASP page
Parse the results in your server code
Return an appropriate response to the browser client
The best you can do, assuming I'm interpreting your question correctly, is "scrape" the HTML returned from the asp page and make proper assumptions about the location and meaning of the text within the markup. I, personally, would strongly advise against developing anything of any kind of robustness based on what amounts to screen scraping, especially considering you don't have access to the .asp file itself. If I've misunderstood your problem, my apologies.

Response Redirect URL returns HTTP Error 400 - Bad Request

I'm a noob when it comes to ASP.NET. I know few basic commands such as Response.Redirect("URL") to redirect my application web page to a different location.
However i receive HTTP Error 400 - Bad Request, whenever i try to use the code shown below
Response.Redirect(Server.UrlEncode(this.Downloadlink));
where this.Downloadlink is a user defined property which returns something like this
http://mdn.vatsag.net/fp;files/DOWNLOAD/VTSetup.exe
If i post this link in the browser, the .exe file pops up (means the link is good)
However this error comes when i use the ASP.NET code.
Any form of response on this issue/reason is deeply appreciated.
See here: http://www.kirit.com/Response.Redirect%20and%20encoded%20URIs
In short: if you quickly want to fix the issue, remove the part of your code that is UrlEncoding the URL!

Is there anything wrong with sending other content along with a 404 error?

For example, day, in a somewhat REST-oriented environment, a request comes in for an object that doesn't exist, like:
GET http://example.com/thing/5
Is there anything wrong with sending back a 404 response who's body is the same as a a different page? For example, responding like:
404 body: [content from "http://example.com/thing/" which is a list of things]
Does it make any sense to do this? Will this cause any problems with certain browsers? Is it confusing to the user? Or is this perfectly fine to do?
Along these same lines, I would have the content of the 404 response match the request's accept headers as best I could. (ie. abide by content negotiation with the user agent)
For example, a xml or json request would get something along the lines of a simple error message and something that says "look here for similar things", while an html request would get an HTML page that has the error message as well as the content of the list page (as I indicated above)
I think it depends on how the Restful web services are being consumed. If I'm programmatically consuming the web service from a different application, then I would want the status code together and a plain text message instead of a message decorated with HTML tags. I mean, say for example, it doesn't make sense to return a bloated 404 content if your user makes the web service call using Curl because the message will not be readable to them.
You could have different "consumes" for each restful webservice. If it's an XML request, then you return 404 and a plain text message. Otherwise, you return the error page content.
I don't see anything wrong with it. In our webservice we always send back a json error object which includes stacktraces and other details about the response. Even on a regular web server, you get at least text which can be displayed in a browser saying that you got a 404 response.

Iframe and http error when loading invalid or protected URL

IM writing some html which provides a preview function for a list of URLs. I want to use an iframe for this functionality,
The issue arises when some of the URLs are broken (returning a 500 error) or when a page contains some authenication process which the requesting user cannot satisfy. In these situations the iframe is trying to display the URL but the content returned in the frame is useless (500 error or authenication error ) to the user.
DOes iframe have any built in error handling for these senarios or is there some other way i can display a generic error page if something happens when loading the iframe?
Thanks
AFAIK, there is no way to directly access the header of a response to a request initiated by an iframe (or indeed, any request) in client side script.
This is slightly convoluted, but I think it would work:
The iframe is initially loaded with a URL that refers to a script on your server, and your pass the actual URL as a GET parameter.
The server side script takes that URL, and sends a HEAD request to it (following 3xx redirects).
If the response code for the HEAD request is >= 200 and < 300, send some script back to the client which changes the iframe's src to the actual URL (you might be able to do something as simple as window.location.href = but I'm not sure without testing).
If the response code is >= 400, send a page that says "This page is not loading at the moment".
If you know PHP/have it available on your server, I can try and provide a code example.

Resources