3

I have the following hyperlink control:

<asp:HyperLink ID="hypTest" runat="server" NavigateUrl="~/Views/TestFolder/TestPage.aspx" >
    Text here
</asp:HyperLink>

But it doesn't find the page - although the page does exist. The error that I get is:

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Views/TestFolder/TestPage.aspx

My guess is that the tilde (~) doesn't work here. If this is the case then why, and how can I get around it?

1 Answer 1

7

If you are using MVC you should use HtmlHelper.ActionLink helper function. You are using a webforms hyperlink control at the moment. Assuming that you have default routing you should be able to use

<%=Html.ActionLink("Text here", "TestPage", "TestFolder")%>

You are currently getting a 404 error as pages within the ~/View folder are blocked by default. You would typically request the page at ~/TestFolder/TestPage.

Sign up to request clarification or add additional context in comments.

2 Comments

Does this mean that I need a dedicated controller for this view (i.e. a TestPage controller)?
If this is a standalone page that is not associated with a controller then you should move it outside the View folder. If you creat a folder called TestFolder and add TestPage.aspx it should work. If a file exists at the url location then it will be served directly to the client and will not go through routing and a controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.