Solved

Streaming inline excel content appears to lose session and replaces excel content with login page

Posted on 2004-09-01
11
291 Views
Last Modified: 2008-01-09
I'm having a problem with an ASP.NET (C#) web application, I'm trying to display an excel spreadsheet inline using the following code:

 Response.Clear();
 Response.AddHeader("Content-Disposition","inline");
 Response.ContentType="application/vnd.ms-excel";
 Response.BinaryWrite(xls);           
 Response.Flush();
 Response.SuppressContent = true;

This works perfectly on my development server but on a production server it opens the Excel viewer inline but instead of the spreadsheet it displays the login page (inside the excel viewer).  An alternative code path that downloads the excel file as an attachment works fine.

So, it seems to be losing the session when  executing on our 2003 server?
0
Comment
Question by:barees63
  • 7
  • 4
11 Comments
 
LVL 10

Expert Comment

by:jnhorst
ID: 11959203
Try changing Response.SuppressContent = true to Response.Close(), or add Response.Close() after Response.SuppressContent = true.

John
0
 

Author Comment

by:barees63
ID: 11959406
Thanks John, I tried both suggestions but they made no difference, still works fine on my server but not on the production server.

Bruce
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 11959644
Check the registry on your server for this string: "application/vnd.ms-excel".

It might be that your dev box has Excel installed, and thus recognizes your content-type but your server does not.  I believe you can install Office Web Components on a server to solve that, but I am not sure what the licensing implications of that are.

John
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 10

Expert Comment

by:jnhorst
ID: 11959645
By "check the registry" I mean search the registry.

John
0
 

Author Comment

by:barees63
ID: 12002523
Thanks John, I've checked that the application/vnd.ms-excel MIME type is registered with IIS and present in the registry under HKEY_CLASSES_ROOT/MIME and even tried installing Excel on the web server.. all to no avail unfortunately.
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12003283
Try changing

Response.BinaryWrite(xls);

to

Response.WriteFile(xls);

where xls is the full file server path to the spreadsheet.  You may need to save the binary stream to a file, call Response.WriteFile(), flush and close the Response buffer, and then you can call

System.IO.File.Delete(xls);

You can access the file system path of the root of the app with Request.PhysicalApplicationPath

John
0
 

Author Comment

by:barees63
ID: 12050962
Thanks again John, Sorry for the delay, I've been pulled onto other stuff over the last few days, I tried that (WriteFile) and it still works correctly on my server but fails in the same way on the other server (opens Excel frame but displays login screen components instead of spreadsheet data).  I think it must an IIS 6 MIME type issue of some sort on that particular machine.

0
 
LVL 10

Accepted Solution

by:
jnhorst earned 500 total points
ID: 12051648
OK, hold on, when you say it shows the login page, do you mean an actual aspx page or do you mean a login dialog, asking for username and password? What kind of authentication are you using?  Let's say you are using Windows authentication and you are allowing anonymous connections to the website.  If in your web.config you have this:

<identity impersonate="true" />

Then your attempt to access the file will be executed under the security context of the IUSR_<machinename> account.  If you do not have this tag, then it will be under the ASPNET account.  Both of these accounts are local accounts, so on your dev box, the account obviously has the necessary persmissions.  But on the server, the local IUSR_... account (if you have the <identity> tag) or the local ASPNET account (if you don't have the <identity> tag) needs to have permissions to the folder in which the file resides on the server.

If you are not allowing anonymous connection and the user authenticates, then they need to be a member of a group that has those permissions.

It's funny how when you look at things again after a few days the issues look different.

John
0
 

Author Comment

by:barees63
ID: 12051823
Thanks John, ok I finally found out what was causing this issue (although not exactly why), we use an "ASP Accelerator" product which is supposed to provide additional compression over IIS built-in compression.  When I disabled this product the Excel stuff started working.  I'm going to accept your answer because it made me go poking about in web.config which made me wonder about the accelerator..  :-)

0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12051835
Great... glad you got it working.

John
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12051841
BTW, check to see where that accelerator program file lives.  If the app accesses a dll somewhere on the file system, it may be a permissions issue there.

John
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question