I'm looking at this so question where the answerer shows a great way to throw a NotFoundException from the Application_Error method in the Global.asax.
This is great however I'd like to modify it a little... just not sure how.
I've got a NotFound view and a Error view in my Shared views folder. I'd like to continue with this and not have to have an ErrorController.
Is there any way to throw a 404 NotFound error when a "controller" doesn't exist, while still not having to have an Error Controller?
IE: if you visit http://example.com/asdf whereby asdf is an invalid controller, I want the "NotFound" view to be loaded from my Shared views directory.
Edit
Basically the issue I'm running into is that of "DRY". I could build an ErrorController, however if I do this, then I have to have the same view in two spots. One in my Views/Error folder for just this situation, and one in my Views/Shared folder whereby I can load up the Error or the NotFound View from any controller.
I also tried this
Private Sub BaseGlobal_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Error
Dim exception As System.Exception = Server.GetLastError
Response.Clear()
Dim httpException As HttpException = TryCast(exception, HttpException)
Dim routeData As RouteData = New RouteData()
routeData.Values.Add("controller", "Events")
If (Not httpException Is Nothing) And (httpException.GetHttpCode = 404) Then
routeData.Values.Add("action", "NotFound")
Server.ClearError()
Dim errorController As IController = New UrbanNow.Core.Controllers.EventsController
Response.StatusCode = 404
errorController.Execute(New RequestContext(New HttpContextWrapper(Context), routeData))
End If
End Sub
Where the EventsController is obviously for events, but tried to load in the NotFound view (hoping it would pull from the shared directory... but I didn't have any luck.