Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi all
 
Im redirecting pages to index.aspx page which is inside a folder employee and the url is www.abc.com/hrms/employee/index.aspx.and my home page is in hr folder hr.aspx problem is when redirecting url with querystring return url
if (Request.QueryString["ReturnUrl"] == null)
{
    returnUrl = "~/hr/hr.aspx"
}
else
{
    returnUrl = Request.QueryString["ReturnUrl"];
}
Response.Redirect(returnUrl);
im using this code.but else part leads to exception return url concatenates with abc folder like www.abc.com/hrms/employee/returnurl instead i want www.abc.com/hrms/returnurl .
if my return url with querysting is like this
www.abc.com/hrms/employee/index.aspx?Returnurl=hr/bonus.aspx" when login error arising with the code given above url redirects to www.abc.com/hrms/employee/hr/bonus.aspx but i want this to direct to www.abc.com/hrms/hr/bonus.aspx
 
why happening so? How to overcome this
 
Thanks in Advance
Amrutha
Posted 29-Jan-13 23:16pm
Edited 30-Jan-13 0:35am
CHill6061.2K
v4
Comments
Rahul Dhoble at 30-Jan-13 5:41am
   
Amrutha , I just you to improve question with some better word include some more examples

1 solution

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

Solution 1

That's because you are using incorrect relative URL.
When you say hr/bonus.aspx, the URL that will be generated will be respective of your current path.
So say you have a site www.example.com.
You are currently on a page somepage.aspx which is inside pages folder - www.example.com/pages/somepage.aspx.
Now if you create a relative URL like hr/otherpage.aspx, your URL will be www.example.com/pages/hr/otherpage.aspx.
 
To solve this issue, you will need to specify the path relative to the root directory. You do that using a leading slash (/).
So instead of hr/bonus.aspx use /hr/bonus.aspx and it should be fine.
 
Let me know if you don't understand.
  Permalink  
v2
Comments
amritha444 at 30-Jan-13 7:21am
   

i understand what you meant .I added a ~/ before returnurl and its working fine. thanks Ankur
Ankur\m/ at 30-Jan-13 7:32am
   
What you had was a string. So I suggested leading slash (/) rather than ~/
Anyways glad that I could help. :)

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,725
1 OriginalGriff 6,696
2 CPallini 5,315
3 George Jonsson 3,589
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 30 Jan 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