Click here to Skip to main content
11,577,494 members (40,627 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET
I am redirecting user from one page to login page...but on login page if user directly do login then he will be redirecting to profile page and if he redirects from different page then he should be redirecting to different than profile..I have done using ReturnUrl query string parameters but i am getting exception when i directly login..Becoz it dont gets ReturnUrl of what shoud i do?
Posted 4-Feb-13 18:14pm

1 solution

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

Solution 1

you have implement your own logic. If user directly goes to login page then you can easily redirect to the page where you want because you know where to redirect ie what is the first page after login.

So Have a check on returnurl if you have returnurl then redirect to returnurl else redirect to first page after login
Member 9579525 at 5-Feb-13 0:44am
thank u....i have tried that but getting exception "Object reference not set to an instance of an object."

//my code

string retrnurl = Request.QueryString["ReturnUrl"].ToString();//exception
if (!string.IsNullOrEmpty(retrnurl))


Brij at 5-Feb-13 1:31am
You code is wrong. Request.QueryString["ReturnUrl"] would return null if it is not there and you cannot use ToString() on null objects. So have a check like
if (Request.QueryString["ReturnUrl"] != null)
string retrnurl = Request.QueryString["ReturnUrl"].ToString();

Member 9579525 at 5-Feb-13 2:19am
now its working...Thanx

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

  Print Answers RSS
0 DamithSL 180
1 OriginalGriff 115
2 Richard MacCutchan 100
3 Abhinav S 90
4 Peter Leow 80
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 681
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 375

Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2015
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