1

In my application I wish to block the ability for users to navigate to specific views from the browser. These ActionResults and by extension Views serve singular basic functions to which I call in my layout with Html.RenderAction("Action","Controller"). In order to handle this, I am using [ChildActionOnly] attribute on the various get requests. How would I go about redirecting these request to my custom 404 instead of the error page?

I have tried setting the ActionResult to private which does send the user to a 404, however doing so causes the Html.RenderActionto fail.

Here is my Web.config logic

<customErrors mode="On" defaultRedirect="~/Error">
  <error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>
Skullomania
  • 2,225
  • 2
  • 29
  • 65
  • You cannot redirect in a `[ChildActionOnly]` method - [Why are Redirect Results not allowed in Child Actions in Asp.net MVC 2](https://stackoverflow.com/questions/2056421/why-are-redirect-results-not-allowed-in-child-actions-in-asp-net-mvc-2) –  Nov 16 '17 at 21:11
  • You might be better served to make a custom data attribute for your "ajax only" action methods that will allow you to redirect if requested directly. Here is a great SO solution I've used before for exactly this problem - https://stackoverflow.com/a/4168806/130387 – Tommy Nov 16 '17 at 23:45
  • There is no Ajax request in this particular case – Skullomania Nov 17 '17 at 00:05

0 Answers0