How does this code work?(Request["ReturnUrl"])

  • Thread starter Thread starter vvkl
  • Start date Start date
V

vvkl

I have readed a example code from MSDN about FormsAuthenticationTicket
calss, but there's a line I can't understand :
'strRedirect = Request["ReturnUrl"];'
What's the mean in which square brackets?

Thank you!

A Chinese student.
 
I can't understant well.
Could you give an example?
I want to know when is the Request["ReturnUrl"]'s value not null?

Marina Levit said:
That is using the indexer for the object to index into it by name.

vvkl said:
I have readed a example code from MSDN about FormsAuthenticationTicket
calss, but there's a line I can't understand :
'strRedirect = Request["ReturnUrl"];'
What's the mean in which square brackets?

Thank you!

A Chinese student.
 
That is a feature of authentication. When you try and access a page
without logging in, asp.net will redirect you to the login page. The
value in the "ReturnURL" value of the query string will be the page
you original requested

I have readed a example code from MSDN about FormsAuthenticationTicket
calss, but there's a line I can't understand :
'strRedirect = Request["ReturnUrl"];'
What's the mean in which square brackets?

Thank you!

A Chinese student.
 
Well, I'm codding a login function.
I've tried and accessed page "CustomerDetail.aspx" without logging in, then
redirected to page "login.aspx" .But, after authenticated, my code dosen't
work.

string strRedirect = Request["ReturnUrl"];
if(strRedirect == null)
strRedirect = "MyDetail.aspx";
Response.Redirect(strRedirect, true);

the value of "strRedirect" always is null.
How can "Request["ReturnUrl"]" get value?

Rad said:
That is a feature of authentication. When you try and access a page
without logging in, asp.net will redirect you to the login page. The
value in the "ReturnURL" value of the query string will be the page
you original requested

I have readed a example code from MSDN about FormsAuthenticationTicket
calss, but there's a line I can't understand :
'strRedirect = Request["ReturnUrl"];'
What's the mean in which square brackets?

Thank you!

A Chinese student.
 
I've tried and accessed page "CustomerDetail.aspx" without logging in, then
redirected to page "login.aspx" .But, after authenticated, my code dosen't
work.
string strRedirect = Request["ReturnUrl"];
if(strRedirect == null)
strRedirect = "MyDetail.aspx";
Response.Redirect(strRedirect, true);

the value of "strRedirect" always is null.
How can "Request["ReturnUrl"]" get value?

You need to put that onto the URL when you call up your page - e.g. if
your client tries to access "CustomerDetail.aspx" and gets redirected
to the login.aspx page, you'll need to do something like:

login.aspx?ReturnUrl=CustomerDetail.aspx

That way, you'll get the "ReturnUrl" in your Request[..] object.

Marc
 
You do me a big favor!
Thank you!

Marc Scheuner said:
I've tried and accessed page "CustomerDetail.aspx" without logging in,
then
redirected to page "login.aspx" .But, after authenticated, my code dosen't
work.
string strRedirect = Request["ReturnUrl"];
if(strRedirect == null)
strRedirect = "MyDetail.aspx";
Response.Redirect(strRedirect, true);

the value of "strRedirect" always is null.
How can "Request["ReturnUrl"]" get value?

You need to put that onto the URL when you call up your page - e.g. if
your client tries to access "CustomerDetail.aspx" and gets redirected
to the login.aspx page, you'll need to do something like:

login.aspx?ReturnUrl=CustomerDetail.aspx

That way, you'll get the "ReturnUrl" in your Request[..] object.

Marc
 
You need to setup your authentication properly. In particular change
the web config such that it denies anonymous logons.

That way ASP.NET will automatically populate the ReturnURL parameter
if you access a page without logging on.

Well, I'm codding a login function.
I've tried and accessed page "CustomerDetail.aspx" without logging in, then
redirected to page "login.aspx" .But, after authenticated, my code dosen't
work.

string strRedirect = Request["ReturnUrl"];
if(strRedirect == null)
strRedirect = "MyDetail.aspx";
Response.Redirect(strRedirect, true);

the value of "strRedirect" always is null.
How can "Request["ReturnUrl"]" get value?

Rad said:
That is a feature of authentication. When you try and access a page
without logging in, asp.net will redirect you to the login page. The
value in the "ReturnURL" value of the query string will be the page
you original requested

I have readed a example code from MSDN about FormsAuthenticationTicket
calss, but there's a line I can't understand :
'strRedirect = Request["ReturnUrl"];'
What's the mean in which square brackets?

Thank you!

A Chinese student.
 
Back
Top