Sandy Westman
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.Respon se.Clear() ; // Get rid of anything queued up
HttpContext.Current.Respon se.Write(" Hello New World");
HttpContext.Current.Respon se.Flush() ;
HttpContext.Current.Respon se.Close() ;
Here is the code
HttpContext.Current.Respon
HttpContext.Current.Respon
HttpContext.Current.Respon
HttpContext.Current.Respon
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
be sure to also add response.buffer = true in the page_load event, or iadd buffer=true in the @Page directive
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
adding response.buffer = true to pageload did not resolve the issue.
Commenting out httpContext.Current.Respon se.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
Commenting out httpContext.Current.Respon
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
</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
ASKER
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.pay pal.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@i ntermi.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>
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
</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"
<meta http-equiv="Pragma" content="no-cache">
</head>
<body onLoad="document.forms.pay
<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@i
<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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
ASKER
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.
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.
ASKER
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.
ASKER
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();
}
}
}
ASKER
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.
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?
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
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!
ASKER
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.Respon se.Clear() ; // Get rid of anything queued up
HttpContext.Current.Respon se.Write(" HelloWorld "); // Emit form with auto submit to transfer from user's browser to PayPal
HttpContext.Current.Respon se.Flush() ; // Flush()/Close() is better than Response.End()
HttpContext.Current.Respon se.Close() ;
HttpContext.Current.Respon
HttpContext.Current.Respon
HttpContext.Current.Respon
HttpContext.Current.Respon
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.Id entity.Nam e 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.
When I run write Thread.CurrentPrincipal.Id
ASKER
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.
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.
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.
ASKER
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) .
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
ASKER
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(payPalStdLi b.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.
Response.Clear();
Response.Write(payPalStdLi
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
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=28bd5941-c458-46f1-b24d-f60151d875a3&displaylang=en
ASKER