download file and redirect page in asp.net - asp.net

I want to write a program where after button click page will be redirected and one pdf file will be download. I am writing the following code under the button click event. but it is showing the error.
Response.TransmitFile("Filename")
Response.Redirect("~/Redirect.aspx")
Response.End()

It is impossible, because file download will get HTTP status 200 (with file in response). Redirect is 301/302, but cannot contain file in response.
Moreover when modern browser receive a file it does not change the current URL.
If you really want to have such effect you have to create something on client side. For example you can use jquery file download which has events after download and on error. More on examples page

Related

How to Refresh page after Response.End

In my ASP.NET application on a button click i am writing a .pdf content dynamically and the I am allowing to download for a User
Now to download i used Response.End() and need to refresh a download count on a page
But due to Response.End it is not happening
Please suggest
And it will never happen - You can not refresh page after Response.End
The way you download the files is not the best one. Use a handler for the download files and a simple anchor to that file.
Examples / Similar :
file download by calling .ashx page
What is the best way to download file from server
Hide modal window after Response.End() in asp.net

Word hyperlinks not opening asp.net files

I have some Word files which need to have hyperlinks. The hyperlinks go to an htm file with an anchor, but that htm file isn't provided via a direct url for security reasons. Rather it is linking to a ashx handler file that retrieves the file and does an response.write to show the html file in the browser. Before it does this, though, it checks to back sure that there's a valid session, and if there isn't then it just redirects to the login page. This works fine when linking from within the ASP.Net site, but when I link to it from a local MSWord file, it apparently doesn't know there's a valid session (even though I've logged in in the browser), and redirects to the login page. Is there any way around this? For compatibility these Word documents need to be in Word 97-2003 format unfortunately...
No. This won't work.
Opening the word file outside of a browser and clicking on the link is going to start a brand new session; regardless of whether you currently have a browser window opened on the site.
Because a new session is starting, the web server will assume you aren't logged in at all. Which, technically, you aren't.

How do I debug step into an ASPX page that requires an XML request?

Is there a way to test sending an XML file as a request to my ASP.Net web page within Visual Studio 2008?
Ok, no one has answered this in a helpful way. I have a situation where I have an ASPX page that I send an XML file too and receive an XML response from. In order to debug this, I need to step into the page while providing an XML request. I This is what I need to figure out how to do?
This is easy. Just create an HTML page that contains a simple submit form, and it's submit action will post-back the XML. In visual studio, all you have to do is attach to process-> and choose the browser window containing your HTML form, and there you go.
You can simply put a breakpoint at the code behind just before sending the file to see that everything at that point is as expected.
From then on, the best way to see what goes over the wire is to use a debugging proxy like fiddler.
Alternatively, there is firebug and its Net tab which will show your requests and responses.

file transfer through iframe not propagating

I'm still rebuilding old ASP to new and iframing certain things that take up too much time.
I'm stuck at a search function that normally returns an excel file (browser asks save or open). the result page for this is now iframed but it does not seem to propagate the file anymore, so no more save-file popup.
I must add that this iframe is being filled through a custom httphandler that posts to the old pages based on certain criterie, the searchcriteria in this case.
does anyone have an idea on how I could make the excel propagate once again?
The way to ensure you get a save-file prompt and not a page, do the following:
Open the file in ASP
Send the MIME header for Excel
Stream out the file from ASP
You may also choose to hold the files outside of the web root so they cannot be downloaded directly.
Here are a few examples: 1 2 3
This may come in handy as well:
How to output an Excel *.xls file from classic ASP
It *seems* like a security issue. What happens if you open the URL which is being loaded in the IFrame in a new browser? To confirm it, you can try opening the URL, and see what happens.

Display loading message and then prompt for open / save

I'm trying to get a page to show a "loading..." message while I create a report and then I'd like to trigger an open / save on the report I've just created.
I can create a static loading page but I don't know how to trigger the open / save dialog.
I could insert an <iframe> but then I would have to save the created report on the server side.
What I'm looking for is a way to just embed the created report into the HTML and let the browser deal with (the report files are Excel and PDF).
Is there a way to do that? I looked at <embed> but it requires a URL, same as <iframe>.
Maybe my best bet is to handle everything in an Http handler and make a first call to generate the report and then do a redirect to display it (and trigger the open / save).
Any ideas?
Are you allowed to use javascript?
You could have javascript on the loading page that either pops up a new window with the report generation or triggers a redirect to the report generation. In the report generation handler you can then set the content-disposition header to force the open/save box.
In the end, I didn't bother with the waiting message. I just point my Silverlight client at the HTTP handler address and wait for it to create it. I had issues with the <embed> tag and the Acrobat Reader plugin (the plugin would time out and not load the report when it was ready) but that doesn't happen at all when the browser waits for the page to load.
So, not an answer but it works.

Resources