Some Times My DotNet Code works fine in Local but not when deployed

HI friends ,

i came through the scenario where my code was working as expected in local when i run it through local host but it was not working as expected when i deployed the code into IIS server.

Generally this issues happen for several reasons one among and most common among them is while using sessions

Example :

if i wrote a peace of code like this

Session[“Test”] =”1″; // here i am assigning session to a string value “1”

so when using it in a condition or so

if i am testing it some what like

Session[“Test”] =”1″;

if(Session[“Test”] == “1”){

Response.Write(“Session named Test value is 1”);

}else

{

Response.Write(“Session named Test value is not 1”);

}

when i run this code in local i will get output like this

“Session named Test value is 1”

but if i run this code after deploying into server i will get output like this

“Session named Test value is not 1”

basically the reason for this is when we deploy this code in server it wont convert session object into string to compare where as this thing happens when you are running code in local machine… i really don’t know the reason behind this behavior. most of the times it will take several hours to find the reason so here in order to get this code work in server also we need to convert the session object which is the solution to this problem

i will solve this problem by writing the if condition like this

if(Session[“Test”].ToString() == “1”)

here i am converting session object into string to compare which will work in both places

 

i will update other reasons also which are going to cause this issue in my next post ……

 

Regards

Santosh Kakani

 

Advertisements

About kakani santosh kumar

Working as Software Engineer in Prithvi Information Solutions having 3 years of Experience in Dotnet Framework ranging from 1.1 to 3.5
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s