How to: Redirect Correctly with ASP.NET Relative URLs

I have an authentication script ( CheckLogin.aspx

), and if any of the credentials do not match my application, it will be redirected (via ) to a denied page ( ). Every time my script runs it gets . Here is a mock file structure of my applications: Server.Transfer

forbidden.aspx

InvalidOperationException: Failed to map the path '/forbidden.aspx'

<root>
..default.aspx
..forbidden.aspx
..<inc>
....scripts.js
..<auth>
....CheckLogin.aspx

      

As you can see, the page is in a folder inside the root, and the page is inside the root itself. The path I say to redirect my application is . CheckLogin.aspx

forbidden.aspx

/forbidden.aspx

+1


source to share


2 answers


Sometimes you need to precede the page path with a tilde to point to the root directory:



'~/forbidden.aspx'

      

+4


source


Are you using "~ / ..." to make sure all your paths are relative?



By the way, you just need to configure the access to the page through the Web.config using tags <location>

. This way you can have some kind of role-based access, without much code.

0


source







All Articles