Server.Transfer in ASP.NET - weired problem

N

Nedu N

Hi All,

I am facing a typical problem in my .NET application with the pop-up script
messages. The thing is that its working fine when i run on my development
machine but not running in expected manner when i move it to Prod
environment. Please have a look at the following code snippet...

//Page name - Add.aspx

private void Page_Load(object sender, System.EventArgs e)

{

//Page load goes here --

}

private void Submit_Click(object sender, System.EventArgs e)

{


// PopUp1

if (row exists with the kay say 'ABC' in database)

{

Response.Write("<script> alert('ABCD already exists!!');</script>");

}

else

{

//code to add the row with 'ABCD' goes here

// PopUp2

Response.Write("<script> alert('ABCD added successfully!!');</script>");


//Redirected to the same page

Server.Transfer("Add.aspx");

}

}

---------

Here the problem is that when i run thei code on my dev server, while adding
the row with ABCD, it gets added succesfully and give the popup saying 'ABCD
added succesfully' and if i try to add the same row again then i get the
'ABCD already exists' message. But when i moved this dll to production box
and it is not giving me the same result. What happens while adding row with
ABCD(by clicking submit button) it adds the row and gives 'ABCD added
sucessfully' and followed by it gives 'ABCD already exists' message also. I
see that the Submit_Click procedure being triggered twice on prodution box.

The dev version in VSNET - 2003 and PORD one is higher version than this
one. Is there any poblem in Server.Transfer while redirecting to the same
page? But it works fine on Test machine. Unfortunately i am not able to
debug on the production box, since i have moved only the dll and the aspx
pages to production box.

Thanks
 
G

Guest

WHich version of IIS You are using. In older version of IIS Server.transfer will not work.

try

Response.Redirect
 
S

Steven Cheng[MSFT]

Hi Nedu,


Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you used the "Server.Transfer" method in your
ASP.NET web application. And the web page worked well on the dev machine,
however didn't work correctly on the production server.
If there is anything I misunderstood, please feel free to let me know.


Based on my research, there does occurs some problem on the Server.Transfer
method. This method is a new method in the IIS5. Also, here are some KB
articles I've found which are focus on this problem(both in .NET 1.1 or 1.0
), there're some different causes may lead to this method's not working :

#FIX: Calling Server.Transfer Skips Execution of Custom HTTP Filters
http://support.microsoft.com/?id=814206

#FIX: Server.Transfer Does Not Invoke IsPostBack in .NET Framework 1.1
http://support.microsoft.com/default.aspx?id=821758

#Postback Event Not Called When RewritePath Uses Server.Transfer or
Server.Execute
http://support.microsoft.com/?id=817036

You may check out the above items and compare it with both of your
enviroments to see whether there're any clues. Also, since I'm not sure
about your actual enviroment, I've tested some code on my side, but haven't
repro the same problem. So I recommend that you try a simpler page which
use the "Server.Transfer" method and use the Response.Write to output some
debug infos so as to see whether there're any thing incorrect or just to
find the runtime difference between the dev server and the prod server. And
here is a page I used to test it, you may have a reference:

---------------------------------ASPX
page--------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ServerTransfer</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td>
<asp:TextBox id="txtInput" runat="server"></asp:TextBox></td>
<td>
<asp:Button id="btnSubmit" runat="server"
Text="Submit"></asp:Button></td>
</tr>
<tr>
<td><FONT face="ËÎÌå"></FONT></td>
<td></td>
</tr>
</table>
</form>
</body>
</HTML>


-------------------------------------code behind page
class------------------------------------
public class ServerTransfer : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtInput;
protected System.Web.UI.WebControls.Button btnSubmit;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Response.Write("<br>Page.IsPostBack:" + IsPostBack.ToString());
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnSubmit_Click(object sender, System.EventArgs e)
{
if(txtInput.Text.Equals("ABCD"))
{
Response.Write("<script> alert('Can not insert ABCD!');</script>");
}
else
{
Response.Write("<script> alert('Insert successfully!!');</script>");
Server.Transfer("ServerTransfer.aspx");
}

}
}


Please try out my suggestion. If you need any help or have any new
findings, please feel free to let me know.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Y

Yan-Hong Huang[MSFT]

Hello Nedu,

Also, I noticed this in your post:
"The dev version in VSNET - 2003 and PORD one is higher version than this
one."

Did you install VS.NET in production machine? If yes, did you install VS
Whidbey Beta? If no, could you please tell us the environment of the
production machine, such as OS version, service pack version, .NET
framework version and etc?

By the way, please also test Response.Redirect. It needs a new request from
the client side. Server.Transfer uses the same request as the original one.

Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Nedu,


Thanks for your followup. As for the the problem in this issue, have you
also checked out the other KB articles(on Server.Transfer not work) I
provided in the former reply? I think they may also be helpful. In
addition, if you still feel vert confused on this problem, do you think it
proper that we look for some other approachs to workaround it? If so,
please feel free to provide the detailed requirement of your problem, I'll
be willing to help you dealing with it. Thanks.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Aarti,

Thanks for your posting. As for the hotfix described in kb, I think you
need to contact the Microsoft Product Support Service for it. As mentioned
in KB:

--------------------
To resolve this problem immediately, contact Microsoft Product Support
Services to obtain the fix. For a complete list of Microsoft Product
Support Services phone numbers and information about support costs, visit
the following Microsoft Web site:
http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

------------------------------

Try get the contact info first and ask for the certain hotfix from PSS.
Thanks.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top