Solved

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

Posted on 2004-09-01
11
284 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
Comment Utility
Try changing Response.SuppressContent = true to Response.Close(), or add Response.Close() after Response.SuppressContent = true.

John
0
 

Author Comment

by:barees63
Comment Utility
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
Comment Utility
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
 
LVL 10

Expert Comment

by:jnhorst
Comment Utility
By "check the registry" I mean search the registry.

John
0
 

Author Comment

by:barees63
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 10

Expert Comment

by:jnhorst
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Great... glad you got it working.

John
0
 
LVL 10

Expert Comment

by:jnhorst
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now