Relative URLs in Code-Behind
-
Hi, I am implementing a mechanism that check a user is logged in before showing the aspx pages. I have tried to implement this in the code behind of the master page of the restricted pages. In case there is no-one logged in the page must redirect to the appropriate "No-Rights" page. The problem is that the master page can be used by pages at different folder levels. How to redirect the response to the correct URL of the page? How to specify the URL relative from the web-application root? Another typical problem here is that when debugging using Visual Studio, the pages are relative to the localhost/PROJECT-NAME/pages. But when deployed the pages are placed directly under HOST/pages. Can anyone help? Thanks, Colin
-
Hi, I am implementing a mechanism that check a user is logged in before showing the aspx pages. I have tried to implement this in the code behind of the master page of the restricted pages. In case there is no-one logged in the page must redirect to the appropriate "No-Rights" page. The problem is that the master page can be used by pages at different folder levels. How to redirect the response to the correct URL of the page? How to specify the URL relative from the web-application root? Another typical problem here is that when debugging using Visual Studio, the pages are relative to the localhost/PROJECT-NAME/pages. But when deployed the pages are placed directly under HOST/pages. Can anyone help? Thanks, Colin
First of all this should have been posted in the ASP.NET Boards[^]. From what I recall, you are going to have to use ~ to go to the root of the directory. i.e. localhost/Project-Name/Restricted/test.aspx = ~/Restricted/test.aspx so even if you were on localhost/Project-Name/Restricted/test.aspx you could reference to the login page with something like this (assuming your login page is in the root of the website), ~/login.aspx
If at first you don't succeed ... post it on The Code Project and Pray.