ianinspain
asked on
500pts: Context.items not working, can you help?
Hi there,
I wonder if anyone can help. I have just migrated an application from visual studio 2003 to visual studio 2005... It all went well... apart from one thing really...
Each page uses a method to transfer information to a web page that is used for errors i.e.
Context.Items[ "error_code" ] = iErrorCode.ToString();
Context.Items[ "error_description" ] = ex.Message;
Context.Items[ "error_page" ] = this.GetType().Name;
Context.Items[ "iduser" ] = "test"
Server.Transfer( "error.aspx" );
It appears to function correctly at this point, the user gets transfered to the error page... but this is where it doesn't work... In code... it basically does the following..
string strErrorCode = Context.Items[ "error_code" ].ToString();
But it appears to be erroring on the first line i.e. the line above... gives the following error
{"Object reference not set to an instance of an object."} "NullReferenceException" was unhandled by user code..
Strange... also the count of Context.Items is 0... i checked it with Intellisense and in the command window...
>? Context.Items.Count
0
Can anyone help?
Thanks in advance
Ian
I wonder if anyone can help. I have just migrated an application from visual studio 2003 to visual studio 2005... It all went well... apart from one thing really...
Each page uses a method to transfer information to a web page that is used for errors i.e.
Context.Items[ "error_code" ] = iErrorCode.ToString();
Context.Items[ "error_description" ] = ex.Message;
Context.Items[ "error_page" ] = this.GetType().Name;
Context.Items[ "iduser" ] = "test"
Server.Transfer( "error.aspx" );
It appears to function correctly at this point, the user gets transfered to the error page... but this is where it doesn't work... In code... it basically does the following..
string strErrorCode = Context.Items[ "error_code" ].ToString();
But it appears to be erroring on the first line i.e. the line above... gives the following error
{"Object reference not set to an instance of an object."} "NullReferenceException" was unhandled by user code..
Strange... also the count of Context.Items is 0... i checked it with Intellisense and in the command window...
>? Context.Items.Count
0
Can anyone help?
Thanks in advance
Ian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi there, thanks... but it didn't help.... although i can understand what you are saying here..
I was watching my Auto watches... and i have all my context.items there... in fact the complete COUNT is 6
and as soon as it does a Server.Transfer( "error.aspx", true );
I lose all my context.items ... in fact nothing is preserved....
I was debugging and watched it... fill the context.items and then transfer to a new page ... so i know it went to a new page.. (error.aspx)
Very strange......
Any ideas?
I presume in Vs 2005 something has changed......
I was watching my Auto watches... and i have all my context.items there... in fact the complete COUNT is 6
and as soon as it does a Server.Transfer( "error.aspx", true );
I lose all my context.items ... in fact nothing is preserved....
I was debugging and watched it... fill the context.items and then transfer to a new page ... so i know it went to a new page.. (error.aspx)
Very strange......
Any ideas?
I presume in Vs 2005 something has changed......
ASKER
Hi sammy,
Just saw your other msg... Yes that is currently what happens on the error page... actually its done slightly different... But as i say the context.items seem to clear when it transfers...
This is what is done in the error.aspx but it errros..... but due to the fact that context.items is empty and doesn't exist
string strErrorCode = Context.Items[ "error_code" ].ToString();
string strErrorDesc = Context.Items[ "error_description" ].ToString();
string strErrorPage = Context.Items[ "error_page" ].ToString();
string strIdUser = Context.Items[ "iduser" ].ToString();
Just saw your other msg... Yes that is currently what happens on the error page... actually its done slightly different... But as i say the context.items seem to clear when it transfers...
This is what is done in the error.aspx but it errros..... but due to the fact that context.items is empty and doesn't exist
string strErrorCode = Context.Items[ "error_code" ].ToString();
string strErrorDesc = Context.Items[ "error_description" ].ToString();
string strErrorPage = Context.Items[ "error_page" ].ToString();
string strIdUser = Context.Items[ "iduser" ].ToString();
Hi
Try Like This
HttpContext.Current.Items
thanks
Try Like This
HttpContext.Current.Items
thanks
ASKER
Yes ... on the errro page .... the context items are lost...
if i do the above.. on the error i get this
>? HttpContext.Current.Items
Count = 0
This is really strange......
if i do the above.. on the error i get this
>? HttpContext.Current.Items
Count = 0
This is really strange......
ASKER
Wow! i found out the problem ... But im a little confused..
Basically Page_Load was loading twice.... and on the second load it would blank out the context.items
I have to set the AutoEventFireup to false... as it was set to true
So it now works BUT when i create a new page ... it sets the AutoEventFireup to true and hence i can execute the page_load .. no probs..
Set it to false stops my NEW page from executing page_load ...
What i can't understand is why settting autoeventfireup to false in my errror.aspx page doesn't stop it from launching page_load...
Do you know why?
Basically Page_Load was loading twice.... and on the second load it would blank out the context.items
I have to set the AutoEventFireup to false... as it was set to true
So it now works BUT when i create a new page ... it sets the AutoEventFireup to true and hence i can execute the page_load .. no probs..
Set it to false stops my NEW page from executing page_load ...
What i can't understand is why settting autoeventfireup to false in my errror.aspx page doesn't stop it from launching page_load...
Do you know why?
string strErrorCode = ((string)(Context.Items("e
if you do a response.write it will output whatever in the error_code from the context item
HTH