Link to home
Start Free TrialLog in
Avatar of Sandy Westman
Sandy WestmanFlag for United States of America

asked on

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

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();
Avatar of Sandy Westman
Sandy Westman
Flag of United States of America image

ASKER

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.
Avatar of LlamaJoe
LlamaJoe

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
ASKER CERTIFIED SOLUTION
Avatar of masterpass
masterpass
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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>


SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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)
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.
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.
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

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.
any chance your website is running in medium or low trust?
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
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();

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
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.
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) .
in IIS - what is the directory path to the application files.  c:\inetpub\webapp\?  or is it \\some-server\sharedfolder\myapp

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