GithubHelp home page GithubHelp logo

andrewdavey / notfoundmvc Goto Github PK

View Code? Open in Web Editor NEW
92.0 92.0 35.0 842 KB

Provides a user-friendly '404' page whenever a controller, action or route is not found in your ASP.NET MVC3 application. A view called NotFound is rendered instead of the default ASP.NET error page.

C# 66.50% CSS 2.41% ASP 0.34% Batchfile 1.25% Smalltalk 2.80% HTML 8.53% JavaScript 18.16%

notfoundmvc's People

Contributors

andrewdavey avatar bkaid avatar daviddesloovere avatar mortan avatar mrmashal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

notfoundmvc's Issues

web.config Transformed Incorrectly On Upgrade

When upgrading the package to 1.4.0, my web.config is being transformed incorrectly.

The allow zombie DOS names line had a transform attribute added to it:

<!-- Allow zombie DOS names to be captured by ASP.NET (/con, /com1, /lpt1, /aux, /prt, /nul, etc) --><httpRuntime targetFramework="4.5" maxRequestLength="32768" xdt:Transform="SetAttributes" relaxedUrlToFileSystemMapping="true" />

A second httpRuntime was added right before the closing of system.web, with a transform attribute in it:

<httpRuntime xdt:Transform="InsertIfMissing" relaxedUrlToFileSystemMapping="true" /></system.web>

And though it seems to just be a formatting difference, the httpErrors section was transformed from:

<httpErrors errorMode="Custom">
  <remove statusCode="403" subStatusCode="-1" />
  <error statusCode="403" subStatusCode="-1" path="/error/forbidden" responseMode="ExecuteURL" />
  <!-- Catch IIS 404 error due to paths that exist but shouldn't be served (e.g. /controllers, /global.asax) or IIS request filtering (e.g. bin, web.config, app_code, app_globalresources, app_localresources, app_webreferences, app_data, app_browsers) -->
  <remove statusCode="404" subStatusCode="-1" />
  <error statusCode="404" subStatusCode="-1" path="/notfound" responseMode="ExecuteURL" />
</httpErrors>

To this:

<httpErrors errorMode="Custom">
  <!-- Catch IIS 404 error due to paths that exist but shouldn't be served (e.g. /controllers, /global.asax) or IIS request filtering (e.g. bin, web.config, app_code, app_globalresources, app_localresources, app_webreferences, app_data, app_browsers) --><remove statusCode="403" subStatusCode="-1" />
  <error statusCode="403" subStatusCode="-1" path="/error/forbidden" responseMode="ExecuteURL" />



<remove statusCode="404" subStatusCode="-1" /><error statusCode="404" subStatusCode="-1" path="/notfound" responseMode="ExecuteURL" /></httpErrors>

NotFoundMvc breaks Glimpse

When NotFoundMvc is installed in an MVC4 application (maybe also for MVC3) the Glimpse handler return an empty page instead of the data.

To reproduce:
File > New Project > MVC4 > Internet Application
Install Glimpse.MVC4 (and build)
Navigate to your site with /glimpse.axd, go to the root and you'll see data
Install NotFoundMvc (and build)
Navigate to the site, no more data in glimpse.

NuGet Package broken

Hello,

Used NuGet to install and it had a big problem on running. When I was doing a 404 page test it gave an error and was looking for a file/reference with a path back to your development computer? Was a wrapper factory file or something like that. I uninstalled so it would run but will try again to capture the error.

MVC Area support

This works well for Application but not seems to work well for Area. If there is any url that is not valid within Area, that make the application to crash due to unhandle exception. Is there anything I'm missing?

Put the NotFound route first in route table

Currently, NotFoundMvc adds "notfound" to the end of the route table.
This is breaking when the web application registers a route like "{somename}"

The solution should be to insert the notfound route at the beginning of the table instead of at the end.

Aaargh - try again

I though it was gonna be relatively easy to bring this back to life with some improvements.
Turns out it's not.

Not behaving well at all when used with Areas

Nice work!

This is a very handy package, but I am finding that it behaves a bit strangely when used with Areas in MVC3.

Basically, it requires that you ALSO put a NotFound view in the shared views folder of the Area. Otherwise, it won't find any NotFound view at all, which causes a StackOverflow exception. I fiddled with this off and on for a couple of days before I figured it out.

I am doing this, using a totally different layout for this second NotFound view. If you put a NotFound view in the shared views folder of the Area, this works rather nicely (as long as you're using GET requests, that is. Still doesn't work right for POSTS for some reason).

This is something I figured out totally by accident. Might be worth mentioning in the readme.

Improve HttpNotFound handling

If it is not possible to intercept MVC's HttpNotFoundResult, it would be better if NotFoundViewResult derived from HttpNotFoundResult. This way I can override the controller action as follows:

public abstract class BaseController : Controller
{
    protected override HttpNotFoundResult HttpNotFound(string statusDescription)
    {
        return new NotFoundViewResult();
    }
}

instead of

public abstract class BaseController : Controller
{
    protected new NotFoundViewResult HttpNotFound()
    {
        return new NotFoundViewResult();
    }

    protected new NotFoundViewResult HttpNotFound(string statusDescription)
    {
        return HttpNotFound();
    }
}

Log Not Found Pages

When using NotFoundMVC...

where is the best place for me to insert code that logs the pages that were not found along with the referer?

In the NotFound.cshtml?

Convert the 403.14 error generated by /Controllers and /Content into a 404 error

It is possible to add an HTTP Errors mapping to a site's root Web.config file that maps the HTTP status code 403.14 to the /notfound error page, in order to give a 404 response for the /Controllers and /Content URLs. I believe that the HTTP/1.1 specification allows for this, due to the definition of a 403 response:

10.4.4 403 Forbidden

The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.

The key is that a 403 response has a different meaning to a 401 Unauthorized error, since the latter means you could authorize and try again but the former means doing so would not make any difference.

Add 404 to nuspec tags

When you do a search in nuget for '404', there are no results.
This could boost the number of installations.

How do I make all 404s be logged to elmah ?

I have been using NotFoundMvc in few of my projects. Also along with this I use Elmah for error hanlding. All 404 are handled by NotFoundMvc, what change do I have to make so that all 404 errors are logged to elmah ?

Hook in ELMAH/logging

Hello.

I've dropped NotFound MVC into a handful of ASP.NET MVC 4 websites and it's been working great.

However, one thing I miss is having ELMAH log not found errors. I've read the documentation and even asked on Stack Overflow (http://stackoverflow.com/q/16126125/11912), but I'm wondering if there's a better way to continue to have ELMAH (or another logging solution) log these errors.

Right now I've added the logging code to the top of the NotFound view, and while it works, it feels kludgey.

Does NotFound MVC support capturing when the catch-all routes are hit?

Attribute Routing and Html.RenderAction causes stackoverflow exception

I have a route define for controller using attribute routing

[RoutePrefix("blog")]
public class BlogController : Controller
{
   [HttpGet]
   [Route("detail")]
   public ActionResult Detail()
   {
      return View();
   }
}

I have a child only action that is being render inside _Layout.cshtml

public class NotificationController : Controller
{
    [ChildActionOnly]
    public ActionResult Index()
    {
       return PartialView("_Notification");
    }
}

inside _Layout.cshtml

@{ 
     Html.RenderAction("Index", "Notification"); 
}

when I do a GET request on /blog/detail, everything works but when I do a POST request on /blog/detail, it throws stackoverflow exception inside _Layout.cshtml where it is trying to render partial view.

If I remove Html.RenderAction from _Layout.cshtml and then do a POST request on /blog/detail, the server reject a call and return 404 in response (expected).

If I keep Html.RenderAction but remove attribute routing and make it work with conventional routing, and then do a POST request on /blog/detail, the server reject a call and return 404 in response (expected).

If I keep both Html.RenderAction and attribute routing but uninstalled NotFoundMvc package. and then do a POST request on /blog/detail, the server reject a call and return 404 in response (expected).

It turns out, there is a bug in the package when using Html.RenderAction with Attribute Routing.

MVC5 Issue with Async

I wish I knew more, I can't seem to figure this one out:

Server Error in '/' Application.
The asynchronous action method 'Register' returns a Task, which cannot be executed synchronously.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The asynchronous action method 'Register' returns a Task, which cannot be executed synchronously.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: The asynchronous action method 'Register' returns a Task, which cannot be executed synchronously.]
System.Web.Mvc.Async.TaskAsyncActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +119 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +27
System.Web.Mvc.<>c__DisplayClass12.b__f() +56
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +256 System.Web.Mvc.<>c__DisplayClass14.<InvokeActionMethodWithFilters>b__11() +22 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +190 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +501 NotFoundMvc.ActionInvokerWrapper.InvokeActionWith404Catch(ControllerContext controllerContext, String actionName) in c:\projects\opensource\NotFoundMvc\src\NotFoundMvc\ActionInvokerWrapper.cs:49 NotFoundMvc.ActionInvokerWrapper.InvokeAction(ControllerContext controllerContext, String actionName) in c:\projects\opensource\NotFoundMvc\src\NotFoundMvc\ActionInvokerWrapper.cs:21 System.Web.Mvc.<>c__DisplayClass22.<BeginExecuteCore>b__1e() +23 System.Web.Mvc.Async.AsyncResultWrapper.<.cctor>b__0(IAsyncResult asyncResult, Action action) +20 System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +20
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +54 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39 System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +54 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +21 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514812
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Remove /views/shared/_layout.cshtml link from Sample App

The Sample App includes the error link /views/shared/_layout.cshtml. This link generates a 500 error because of the underscore at the start of the file name, and there appears to be no way to intercept the error to turn it into a 404 error. Given this, it seems reasonable to me to remove the link and instead rely on the site dealing with the error however it deals with 500 errors generated by the ASP.NET framework (as opposed to the ASP.NET MVC framework). In other words, I don't think that this scenario is in the remit for the NotFound Mvc package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.