Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Response.Redirect("~/UserDetails.aspx?Id=" + Session["Id"].ToString());

What this line do?

What Is Id?
Posted
Updated 21-Jun-11 23:49pm
v2
Comments
Sandeep Mewara 23-Jun-11 5:00am    
Dude you need to pick a book and read instead of posting code and asking about each and every line!

Id is the querystring parameter, This will be redirected to the next page and the id value can be used as the parameter.
See http://en.wikipedia.org/wiki/Query_string[^] for more information on query strings.
 
Share this answer
 
Comments
Dylan Morley 22-Jun-11 5:08am    
lol, same link
It's saying redirect to the UserDetails page and pass in a query string [^] with a name of 'Id' and the value is retrieved from the Session.


Basically, when the UserDetails page loads, it will be able to retrieve the Id passed to it and load up the User that matches the Id.
 
Share this answer
 
Comments
Abhinav S 22-Jun-11 5:11am    
Same link. So my vote of 5. :)
Dalek Dave 23-Jun-11 3:39am    
Spot on!
1. The Redirect method causes the browser to redirect the client to a different URL.

2. In short anything after ? will be categorized into query string as name and value. There can be multiple query string. In this case ID is the first one.

for detailed understanding of URL you can go through URL Specification[^]
 
Share this answer
 
Comments
Dalek Dave 23-Jun-11 3:39am    
Yep!
As others have explained, ID in this case refers to the Session variable, and to the query string. Now, you may be asking yourself why the user would need to pass the variable across - after all, you already have it in the session, so the page being redirected to (which belongs to the same site) should be able to pick that up.

The answer is because a session is volatile. In other words, you have no guarantee that the session will continue to be there when the redirect completes. This is a fairly naive piece of code, because it also assumes that the session value is there when the call is issued - there's no guarantee that this is true; if a page has been left sitting unattended for a long period of time, the session could well have been recycled.
 
Share this answer
 
Hi
Starting First Stage:- Session["Id"].ToString());

This is using for maintain session in your application.

Firstly you check where id exists as paramerter in your application

Like ID=10;

session["id"]=id;
now session[10]

Response.Redirect("~/UserDetails.aspx?Id=" + Session["Id"].ToString());

on your explorer you see "userdetails.aspx?id=10"

this is basically used for one page value send to another page...

Thanks
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900