Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response object failing? 1

Status
Not open for further replies.

SMerrill

Programmer
Jan 19, 2002
145
US
Hey, this used to work, but when I execute
Code:
Response.Redirect "url"
in my ASP page, I am getting the following error:

Code:
Response object error 'ASP 0156 : 80004005' 
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.

I don't get it. The URL is relative addressing, and it's always worked. Now it doesn't.
Shaun Merrill
--Shaun Merrill
 
P.S. It also fails when I use ...

Response.Cookies("A")="B"

... but ...

Response.Write "Msg"

... doesn't fail. --Shaun Merrill
 
The error message explains your problem exactly

>> Any http header modifications must be made before
>> writing page content.


Those two lines you posted must be placed at the top of your file before any HTML text or Response.Write calls

does that help?
-pete


 
Thanks; yes it does. The funny thing is that the IIS built in to XP Pro was happy to accept the code, but when I implemented the same code in IIS for NT4, I got that error.

Nonetheless, here is the neat ASP login form I wrote. It asks the database if the user exists and if the user has writing priviledges, then it pokes them into the cookie and moves on to the next form.

The fixes you suggested are implemented in this ASP code, so it is ready to use.

Code:
<%@LANGUAGE=&quot;VBScript&quot; %>
<%
  dim sUID
  dim sReadOnly
  dim IsFound
  dim IsPosted
  dim oRst  
  const WFDSN = &quot;Provider=SQLOLEDB.1;Persist Security Info=False;User ID=DOIT;Initial Catalog=ChangeManage;Data Source=DOITRPT1&quot;
  
  sUID = ucase(Request.Form(&quot;uid&quot;)) 'Empty string if the form has not been posted

  IsPosted=False

  if sUID<>&quot;&quot; then 'The form has just been posted
    IsPosted=True
	'Look up the username in the database
	set oRst = Server.CreateObject(&quot;ADODB.Recordset&quot;)
	oRst.ActiveConnection = WFDSN
	oRst.Source = &quot;SELECT CanChange from TeamMembers WHERE UserID='&quot; & sUID & &quot;'&quot;
	oRst.Open,,adOpenForwardOnly,adLockReadOnly
	IsFound = False
	if not (oRst.EOF or oRst.BOF) then 'User was found in the database
	
	  IsFound=True
      Response.Cookies(&quot;uid&quot;)=sUID
      
	  if oRst.Fields(&quot;CanChange&quot;)=True then 'Is a power user
        Response.Cookies(&quot;ReadOnly&quot;)=&quot;False&quot;
      else
        Response.Cookies(&quot;ReadOnly&quot;)=&quot;True&quot;
      end if
      Response.Redirect &quot;Default.htm&quot;	 'Outa here
    else
      Response.Cookies(&quot;uid&quot;)=&quot;&quot;
      Response.Cookies(&quot;ReadOnly&quot;)=&quot;&quot;
    end if
    set oRst = nothing
  end if
%>
<html>
	<head>
		<meta name=&quot;VI60_defaultClientScript&quot; content=&quot;VBScript&quot; />
		<script language=&quot;VBSCRIPT&quot;>
			SUB Set_Focus
			  form1.uid.focus()
			END SUB
	    </script>

<meta name=&quot;Microsoft Theme&quot; content=&quot;blends 011, default&quot;>
</head>
	<title>Change Management System</title>
	<body LANGUAGE=&quot;vbscript&quot; onload=&quot;Set_Focus&quot;>
		<h1>Change Management System</h1>
		<form action=&quot;login.asp&quot; method=&quot;post&quot; id=&quot;form1&quot; name=&quot;form1&quot; align=&quot;left&quot;>
		    <p><hr /></p>
				<i>If you wish to make changes to the records 
				   in the Change Management System,
				   you must log in.<br>If not, simply 
				   <a href=&quot;default.htm&quot;>continue</a> 
				   as a read-only, anonymous user.
				</i>
			</p>
		    <table cellspacing=&quot;2&quot; cellpadding=&quot;2&quot; border=&quot;0&quot;>
				<tr>
					<td>User Name</td>
					<td>
						<input name=&quot;uid&quot; id=&quot;uid&quot; tabindex=&quot;1&quot;>
					</font></td>
				</tr>
				<tr>
					<td>
					<td>
						<input type=&quot;submit&quot; name=&quot;login&quot; value=&quot;Login&quot; style=&quot;WIDTH: 154px; HEIGHT: 24px&quot; id=&quot;login&quot; tabindex=&quot;2&quot;>
					</td>
				</tr>
			</table>
		</form>
<%
	if not IsFound and IsPosted then 'The user wasn't found above
%>
		<font color=&quot;red&quot;>
			<i>
				<div id=&quot;divErr&quot;>User Not found</div>
			</i>
		</font>
		<h3>
			<font color=&quot;red&quot;>
				<i>Login Failed, Please Try Again.</i>
			</font>
		</h3>
<%
	end if
%>
	</body>
</html>
--Shaun Merrill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top