Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-01
11
Medium Priority
?
316 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 1500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

636 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