2

I have a VS .net project that uses .net mvc 5 with razor views so the majority of the views use the .cshtml @.. syntax

How do I customize the 404.aspx page to use to older <%= %> syntax inline? For example in my 404.aspx page when I try to use <%=Url.Action.. I get an error stating the name Url doesn't exist in the current context. I've set-up customErrors in the web.config which is working fine, but can't get inline logic in the 404.aspx to work.

How should I set-up the 404.aspx page?

<%@ Page Language="C#" %>

<% Response.StatusCode = 404; %>

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Page Not Found</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
    <!-- Error Page for ASP.NET 404 Not Found Errors -->
    <div class="navbar navbar-inverse navbar-static-top" id="top-navbar">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="<%=Url.Action("Index", "Default", new { area = "" })%>">
                    Link
                </a>
            </div>
        </div>
    </div>
    <div class="container">
        <h1>Page Not Found</h1>
        <p>Sorry, but the page you were trying to view does not exist.</p>
    </div>

</body>
</html>
Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
  • You can't use `Url.Action` since it needs routing and `aspx` is handled through a different request pipeline. I would just hard-code it in and it should work. – beautifulcoder Jan 18 '15 at 23:49
  • Might be useful - http://stackoverflow.com/questions/310580/how-can-i-make-a-catch-all-route-to-handle-404-page-not-found-queries-for-asp – Netferret Feb 10 '15 at 09:46

0 Answers0