Solved

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

Posted on 2004-09-01
11
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

691 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