Solved

Response.write not working when deployed to IIS.  Works locally.

Posted on 2010-09-07
24
1,629 Views
Last Modified: 2012-05-10
I am trying to use a code sample that calls response.write.  When I run my application locally in Cassini I get back a page with the string that I used when calling the write method.  When I deploy it to my IIS 6 box and view the same page in the same browser the page comes back empty.  I have debugged it on the server and confirmed that the response.write block is being called.  I have confirmed that the file versions on my local machine and those installed on the server are the same.  i have restarted IIS.

Here is the code

            HttpContext.Current.Response.Clear();       // Get rid of anything queued up
            HttpContext.Current.Response.Write("Hello New World");  
            HttpContext.Current.Response.Flush();      
            HttpContext.Current.Response.Close();
0
Comment
Question by:sanw2020
  • 14
  • 8
  • 2
24 Comments
 

Author Comment

by:sanw2020
ID: 33623372
I wanted to give my larger picture issue for a moment.  I am trying to compose a page that will return a form with hidden fields and then post that form to paypal.  I've found several examples of this method of requesting from paypal such as http://www.netomatix.com/Development/PostRequestForm.aspx.  When I run the project locally on my box it works like a charm.  When I deploy it to the server it just returns a blank page instead of a form with hidden fields that posts to paypal.  My hello world example is just to help isolate the cause.  I am seeing the same behavior where it works locally, but the server returns a blank page with the code I posted earlier.
0
 
LVL 5

Expert Comment

by:LlamaJoe
ID: 33623921
try using Fiddler and see what is actually being returned to the browser.  I'm guessing that your server is not configured for buffering (there's a checkbox in IIS to allow buffering - but it is checked by default)

be sure to also add response.buffer = true in the page_load event, or iadd buffer=true in the @Page directive
0
 
LVL 21

Accepted Solution

by:
masterpass earned 125 total points
ID: 33623960
Can you just take this line

HttpContext.Current.Response.Close();

from the above code and try again
0
 

Author Comment

by:sanw2020
ID: 33629199
adding response.buffer = true to pageload did not resolve the issue.
Commenting out httpContext.Current.Response.Close(); did not resolve the issue.  
On the server in IIS for this website under the home directory tab, after clicking the configuration button and going to the option tab, the enable buffering is already checked.

This site utilizes a content management system that redirects page requests.  On the server in fiddler I get (I am new to fiddler)

HTTP/1.1 302 Found
Date: Wed, 08 Sep 2010 17:07:36 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Location: /Checkout
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 128

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="%2fCheckout">here</a>.</h2>
</body></html>


Followed by

HTTP/1.1 200 OK
Cache-Control: private
Date: Wed, 08 Sep 2010 17:07:38 GMT
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Vary: Accept-Encoding
Content-Length: 0

0
 

Author Comment

by:sanw2020
ID: 33630788
Thought it may be helpful to post fiddler results from cassinni request (where it is working)

HTTP/1.1 302 Found
Server: ASP.NET Development Server/9.0.0.0
Date: Wed, 08 Sep 2010 19:39:25 GMT
Location: /Checkout
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 128
Connection: Close

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="%2fCheckout">here</a>.</h2>
</body></html>


And then....

HTTP/1.1 200 OK
Server: ASP.NET Development Server/9.0.0.0
Date: Wed, 08 Sep 2010 19:39:50 GMT
Transfer-Encoding: chunked
Cache-Control: private
Content-Type: text/html; charset=utf-8
Connection: Close

3f6
<html>
<head>
<meta http-equiv="Expires" content="0">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
</head>
<body onLoad="document.forms.paypal.submit()">
<form ID="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="item_name" value="Cart" />
<input type="hidden" name="item_number" value="Cart" />
<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="amount" value="235.00" />
<input type="hidden" name="cpp_header_image" value="http://www.mysite.org/images/logo.gif" />
<input type="hidden" name="business" value="troy.d_126784_biz@intermi.com" />
<input type="hidden" name="return" value="http://localhost:29711/Pages/Cart/Thanks.aspx" />
<input type="hidden" name="notify_url" value="http://localhost:29711/Pages/Cart/IPN.aspx" />
<input type="hidden" name="shipping" value="0.00" />
</form>
</body>
</html>


0
 
LVL 5

Assisted Solution

by:LlamaJoe
LlamaJoe earned 375 total points
ID: 33631481
assuming this is in a aspx page - and not a sub-component or dll - can you take out the HttpContext.Current and just use Response.Write().  you also don't need the response.flush unless you are trying to "paint" the screen.

response.end will flush the current buffer, so you don't need to call it.
0
 
LVL 21

Expert Comment

by:masterpass
ID: 33633104
Also, if you were using IE all the time for checking, I would ask you to remove the response.close and then try on another browser as well (try firefox)
0
 

Author Comment

by:sanw2020
ID: 33635803
Actually it is a subcomponent. I'm including the codebehind for my page, and this is an example subcomponent that I found that I am trying to use:
http://code.msdn.microsoft.com/webguild/Release/ProjectReleases.aspx?ReleaseId=3970
It's in this subcomponent that the Response.Clear, Write, Close and Flush are being called.
0
 

Author Comment

by:sanw2020
ID: 33635882
I tried removing the response.close and got the same behavior in firefox and IE.  Works when I debug in visual studio.  But when I deploy to the server, restart IIS and test I get nothing back.
0
 

Author Comment

by:sanw2020
ID: 33635898
Here is the codebehind for the page.
using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using BMI.CRM.CustomerPortal.BO.Concrete ;

using BMI.CRM.CustomerPortal.BO.Abstract ;

using System.Configuration;





namespace Site.Pages.Cart

{

    public partial class Checkout : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            Response.Buffer = true;



            PayPalCart cart = (PayPalCart) BMIUtility.StaticWebUtility.GetCart(Session);

            var payPalStdLib = new PayPalStdLib

            {

                Environment = PayPalStdLib.Env.Sandbox,  // TODO: Set to Live for production

                Business = (string)(Session["PayPalEmail"] ?? ConfigurationManager.AppSettings["PayPalAccount"]),

                Cmd = PayPalStdLib.Cmds.Xclick,

                CppHeaderImageUrl = "http://www.MySite.org/images/logo.gif",

                CancelReturnUrl = string.Empty,

                Return = "Thanks.aspx",                 // Url to return to after checkout

                NotifyUrl = "IPN.aspx",                 // Accessible Url from PayPal

                ItemNumber = "Cart",

                ItemName = "Cart",

                Amount = cart.GetTotal(),

                Shipping = 0,

                Quantity = 1                             // TODO: support multiple quantities

            };







            payPalStdLib.RedirectToPayPal();

            

        }

    }

}

Open in new window

0
 

Author Comment

by:sanw2020
ID: 33636039
I think I just found something that may be very helpful. This link

http://code.msdn.microsoft.com/webguild/Release/ProjectReleases.aspx?ReleaseId=3970
Has source code for a functional application.  When I run it in visual studio it works fine.  When I deploy it to the server it does not.
This was the example that I used to build mine but I hadn't thought to test it for the same behavior before.  Hopefully with a complete solution someone will be able to help me narrow down the problem.
I've got to believe there is some kind of setting in IIS that I need to change.
Thank you very much to everyone for their suggestions.
0
 
LVL 5

Expert Comment

by:LlamaJoe
ID: 33636832
any chance your website is running in medium or low trust?
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:sanw2020
ID: 33637105
I've never modified a trust level before, but I checked the web.config and machine.conifig and there was no trust element which I believe means it's using a default of full trust.
0
 
LVL 5

Assisted Solution

by:LlamaJoe
LlamaJoe earned 375 total points
ID: 33639023
I copied the sample codecamp project to my machine, compiled it, and copied it to a remote IIS machine - I was able to bring up the PayPal page with no problem (on all examples)

try checking the permissions for the account that is running the page in IIS - I noticed that one of the examples tries to write to a local log file - so the user will need read, write and execute rights on the local folder on the web server.
0
 

Author Comment

by:sanw2020
ID: 33642753
LLamaJoe,

I tried moving the site to another server we have and it ran fine for me.  I tried moving it to another server in the same domain as the one I'm having problems with and get the same results (Doesn't work).  When you mentioned checking the permissions for the account I assume you mean the account on the app pool.  I tried setting this to the local administrator account and it didn't resolve the issue.  I have also tried the predefined Network Service and Local System.  I'm allowing annonymous access to the site and accessing it from inside and outside the domain (Same results) so I don't think the active directory account of the user accessing the site is coming in to play.  

I'm really at a loss.  I had one of my network guys take a look at the settings in IIS between the server that works and the one that doesn't and we can't find any differences.  The server that works is on my primary domain at work, and both the servers that don't are on a development subdomain.  We are considering creating a new server image to start from scratch on that domain to see if we can isolate the issue.  The only other thing that could possibly be an issue is that both of the broken servers are hosting Microsoft CRM and the one that works is not.  We will test on the new server before installing CRM and then again after.

If anyone else has any other troubleshooting suggestions in the meantime they would be appreciated.  I'm going to be off until Monday.  Thanks again!
0
 

Author Comment

by:sanw2020
ID: 33642811
Trying to isolate the issue I tested that these four lines in a new page cause this behavior so I don't believe it is related to the log file or anything more complicated found in that solution.  Response.Write is not working on some servers and is working on others.

            HttpContext.Current.Response.Clear();       // Get rid of anything queued up
            HttpContext.Current.Response.Write("HelloWorld");   // Emit form with auto submit to transfer from user's browser to PayPal
            HttpContext.Current.Response.Flush();       // Flush()/Close() is better than Response.End()
            HttpContext.Current.Response.Close();

0
 
LVL 5

Assisted Solution

by:LlamaJoe
LlamaJoe earned 375 total points
ID: 33646494
HTTPContext runs under the thread identity of the caller - if the dll is somehow switching identities - then it would lose access to the context.

try adding a new method to the component and have it return the value of the Thread.CurrentPrincipal.Identity.Name

then display this is a page - and see if it is the same as the webpage
0
 

Author Comment

by:sanw2020
ID: 33668447
Through testing I've eliminated anything that the dll in that code example is doing as the issue.  I can create a brand new page with a button that just runs those four lines and it does the same behavior.  That should eliminate the need to look deeper into the .dll's of the larger project for a cause.

When I run write Thread.CurrentPrincipal.Identity.Name to a label in Cassinni I get mydomain/myusername.  When I run it on the server that isn't working it is empty (even if I run the website locally on that server).  I am not sure what that tells me or how to fix it.  The servers that don't work have all been on a different domain than the servers that do.  I am still trying to set up a fresh server on that domain to see if a newly created server does this behavior.
0
 

Author Comment

by:sanw2020
ID: 33668503
I hope this may be helpful because you had concerns about HTTPContext.  The following code in a new page's button click event produces the same results.  (No external .dll's involved).

            Response.Clear();
            Response.Write("HelloWorld");
            Response.Flush();
            Response.Close();

It works on some servers and not others.
0
 
LVL 5

Expert Comment

by:LlamaJoe
ID: 33668678
any chance your website is located or referenced as a UNC path in IIS?

part 2 - if anything has already been flushed to the browser, then Response.Clear will not work (and the code might be stopping right there).

try taking the response.clear() out of the code and see what happens.
0
 

Author Comment

by:sanw2020
ID: 33673251
LLama,

Thanks again for sticking with me on this.  I'm not sure what you are asking in your first question.  I've tried accessing this site via External IP, Internal IP, Machine Name, and on the machine using localhost.  I get the same results in all cases.

I tried removing response.clear() and get the same results.

I have successfully gotten it to work on a machine running Microsoft CRM (One of the things the two broken servers have in common) .
0
 
LVL 5

Expert Comment

by:LlamaJoe
ID: 33678165
in IIS - what is the directory path to the application files.  c:\inetpub\webapp\?  or is it \\some-server\sharedfolder\myapp

0
 

Author Closing Comment

by:sanw2020
ID: 33683141
I never did figure out why it behaves differently on some servers than others but I was able to get this working by doing a combination of things.  I restructured the code so I could use response.write instead of HttpContext.Current.  I also had to remove response.buffer = true.  I then was able to get it working with the following lines.
            Response.Clear();
            Response.Write(payPalStdLib.GetHtml());
            Response.End();

Thank you everyone for your help.  I'm not sure why these servers weren't working the same as others I tested, but at least I'm able to move forward.
0
 
LVL 5

Expert Comment

by:LlamaJoe
ID: 33687038
hmm, sorry we couldn't figure it out - if you want to really deep dive, download the IIS debug diagnostics tools.  

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=28bd5941-c458-46f1-b24d-f60151d875a3&displaylang=en
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

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

708 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

12 Experts available now in Live!

Get 1:1 Help Now