Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.I Have a Confirm-user.aspx in asp.net bound to master page.the Confirm-user page is in folder(Manage_pages).I have the sidebar in master page. and use this code for list all page that user can access:

<div id="sidebar">
                    <ul>
                        <li>
                            <h2>title</h2>
                            <ul>
                            <% foreach (DAL.Page page in pageList)
         {%>
         <% Response.Write("<li><a href="+page.PageAddress+">"+page.PageName+"</a></li>"); %>
        <% }%>


                            </ul>
                        </li>
                    </ul>
                </div>



the problem is that when I click on Confirm-user page link I go to this page successfully

http://localhost:2112/Manage_pages/ConfirmUser.aspx

.But when I click on link again it does not work and go to :

http://localhost:2112/Manage_pages/Manage_pages/ConfirmUser.aspx

please help me. thanks.

What I have tried:

how to add some conditional code for redirect to current page in asp.net
Posted
Updated 1-Oct-17 22:50pm
Comments
Kornfeld Eliyahu Peter 1-Oct-17 5:10am    
The URL you create here is relative to the current page...
rezaeti 1-Oct-17 7:40am    
hi . can you say more detail.

1 solution

Response.Write("<li><a href="+page.PageAddress+">"+page.PageName+"</a></li>");


If "page.PageAddress" is "Manage_pages/ConfirmUser.aspx" then that's a relative url, ie relative to the current page, so "Manage_Pages" is a level below the current page. If you're on the home page this is "Manage_pages/ConfirmUser.aspx" as you'd expect. However when you're on ConfirmUser then the page is considered a child of that folder, so "Manage_pages/Manage_pages/ConfirmUser.aspx" which is what you're seeing.

What you want is an absolute reference that is always interpreted as from the root of the site and that can be done at it's simplest like

Response.Write("<li><a href=/"+page.PageAddress+">"+page.PageName+"</a></li>");


I added a "/" to the front of the url and that turns your url into "/Manage_pages/ConfirmUser.aspx" which looks for the Manage_pages folder from the root of the website no matter where you are.

There are better ways though such as using Page.ResolveUrl or there are things like

VirtualPathUtility.ToAbsolute Method (String) (System.Web)[^]

your code will also have problems if there are spaces in your url. I would do all this work at the point that the list of urls is generated, do work on them to make sure they are absolute then rather than writing this code on the aspx page.
 
Share this answer
 

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