Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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
Updated 30-Jan-13 0:35am
v4
Comments
RDBurmon 30-Jan-13 5:41am    
Amrutha , I just you to improve question with some better word include some more examples

1 solution

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.
 
Share this answer
 
v2
Comments
amritha444 30-Jan-13 7:21am    
i understand what you meant .I added a ~/ before returnurl and its working fine. thanks Ankur
Ankur\m/ 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)



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