Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB ASP.NET
Hello Everyone,
 
There is one problem regarding Page Redirection. Here is Sample code
1) Database Connection -> Done
2) Insert Data -> Done
3) Add value inside Session variable -> Done
4) Redirect to success page -> Problem come up Here Frown | :(
 
Default1.aspx:
......
Dim success As String = "Success"
......
'btn_Click Event
    Try
        sqlCom.ExecuteNonQuery()
        sqlCon.Close()
        Session("success") = success
        MsgBox(Session("success") 'Msg Prints Properly

        modifyXmlData(filePath); ' Modifies the attribute value
        '1st Approach
        Response.Redirect("default2.aspx", False)
        '2st Approach
        'Server.Execute("default2.aspx", False)
        Catch ex As Exception
        MsgBox("Exception" + ex.Message)
        'lbl_Success.Text = ex.Message
    End Try
End Sub
 
Protected Sub modifyXmlData(ByVal filepath As String)
        Dim strPath = Server.MapPath(filepath)
        Dim xmlFile = XDocument.Load(strPath)
 
        xmlFile.<root>.<ListItem>.Where(Function(f) _
                        f.@value = ddl_SelectedValue).@visited = "Yes"
        xmlFile.Save(strPath)
End Sub
 
defualt2.aspx
 
inside page_Load()
'MsgBox(System.Web.HttpContext.Current.Session("success")) ' o/p : Empty
Dim success As String = Session("success").toString
MsgBox(success) 'o/p : Empty
End Sub
 
1st Approach : Using Response
It Redirects to next Page properly but when I am trying to get Session value
It Shows Empty always..
 
2nd Approach : Using Server
I am afraid with this option, because It holds the session value and at the time of redirection it executes the Page_Load event of Default2.aspx but after page_load Control get destroyed and stays on my Default1.aspx (first page)
 
instead of Server.Execute I used Server.Transfer but it raise the Exception -" thread is being aborted"
 
Thanking you
Please show me way to rectify this problem
Posted 19-Apr-13 0:58am
Edited 23-Apr-13 0:27am
v5
Comments
Prasad Khandekar at 19-Apr-13 6:08am
   
What's the value of variable success? Are you storing a null value?
Rohit More at 19-Apr-13 6:10am
   
No , "success" is string variable and holds "Success" string.
Yuvaraj Arasu at 19-Apr-13 6:49am
   
Hi,Can you show that ," how you are getting session variable 'success' value at 'Default2.aspx' page ?"
Rohit More at 19-Apr-13 7:16am
   
yeah sure.
 
inside page_Load()
'MsgBox(System.Web.HttpContext.Current.Session("success")) ' o/p : Empty
Dim success As String = Session("success").toString
MsgBox(success) 'o/p : Empty
End Sub
Yuvaraj Arasu at 19-Apr-13 8:03am
   
I have tried with your method here, No problem and works fine.. Can you just print the Session.sessionid on both pages.. to check whether both ids are same.. check & inform us..
Rohit More at 19-Apr-13 8:17am
   
Hello Sir,
just tried this thing.
 
when I used Response.Redirect() method -> Session Id gets Different
and when I use Server.Execute() method -> Session Id is Same but that Page (default2.aspx) didnt appear.
Rohit More at 19-Apr-13 8:56am
   
If add this Line before ie
 
Response.AddHeader("P3P", "CP=""CAO PSA OUR""")
Response.Redirect("default2.aspx", False)
 
Then I got same Session Id . but Value is null

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try
 session["success"]="success"; 
beacause if you dont use quotes than success will be considered as a variable. Using this you can directly assign string to session.
  Permalink  
Comments
Rohit More at 19-Apr-13 7:44am
   
Thank you for you kind reply Sir :),
but success is not direct String its String Variable....!
Rohan Leuva at 19-Apr-13 7:45am
   
have you tried debugging your code? what value you are assigning to that variable?can you show us the code you assigning the variable and retreiving the session at the redirected page?
Rohit More at 19-Apr-13 7:50am
   
default1.aspx
Dim success As String = "Success"
...
try
....
Session("success") = success
MsgBox(Session("success") ' O/p: Success
Response.Redirect("default2.aspx", False)
catch ex As Exception
MsgBox("Exception" + ex.Message)
End Try
 
defualt2.aspx
 
inside page_Load()
'MsgBox(System.Web.HttpContext.Current.Session("success")) ' o/p : Empty
Dim success As String = Session("success").toString
MsgBox(success) 'o/p : Empty
End Sub
 
Yes Sir I tried debugging, session get destroyed after redirection.
even I used that variable in multiple functions before redirection.
Rohan Leuva at 19-Apr-13 7:56am
   
have you assigned anywhere a session timeout?try direct assignment as i said before,and check the RETRIEVED value at second page by debugging.
Rohit More at 19-Apr-13 8:07am
   
well, as timeout concern I removed this but no change, and
about assigning direct string like Session("success")="Success", I tried before but no output.
 
The strange thing is that , as I mentioned above in my question,
when I use Server.Execute("default.aspx", false), It holds the Session values and even it do visit to another page (default2.aspx) Page Load event but it always shows default1.aspx page.
dont know why this? In default2.aspx does not contain any comparison and all kinds of stuff. there I am simply print Session variable and print "Thank you" message
Rohan Leuva at 19-Apr-13 8:11am
   
have u look at this link http://stackoverflow.com/questions/1074912/does-response-redirect-use-the-same-session-or-start-a-new-one
Rohit More at 19-Apr-13 8:29am
   
just checked this link.
I checked session id of both pages so results are
when I used Response.Redirect() method -> Session Id gets Different
and when I use Server.Execute() method -> Session Id is Same but that Page (default2.aspx) didnt appear.
 
Everything is running within single Web Application. so , I think that situation is not applicable for this situation.
Yuvaraj Arasu at 19-Apr-13 9:05am
   
Please show me your web.config file , and show me the .aspx design page too
Rohit More at 23-Apr-13 5:32am
   
I have traced out my problem, just I have modified my Question.
now problem is that if I remove modifyXmlFile()function then it works fine. but if I includes it then session gets lost.
 
and whatever I am modifying xml file, it contains around 15000 elements.
basic structure of my xml file is as following

<ListItem visited="No" value="ABC"/>
<ListItem visited="No" value="PQR"/>
..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 240
2 DamithSL 200
3 Raul Iloc 185
4 Richard MacCutchan 175
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100