Click here to Skip to main content
12,761,046 members (27,372 online)
Rate this:
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 19: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 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 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2017
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