Giter VIP home page Giter VIP logo

worlddomination.web.mvc.errorhandling's Introduction

Archived - 10/04/2021


A nice way to offer Razor-Views Error Pages.#

Steps

  1. File -> New -> MVC Project.
  2. Install-Package MagicalUnicorn.MvcErrorToolkit
  3. Open up Global.asax or FilterConfig.cs, where the HandleErrorAttribute is getting added. Delete or comment this out.
  4. Add your custom error files to web.config. Eg.
    <error statusCode="404" redirect="~/views/error/404.cshtml" />`
    <error statusCode="401" redirect="~/views/error/401.cshtml" />
    <error statusCode="500" redirect="~/views/error/500.cshtml" />
</customErrors>```

.5. Based on where you've defined your custom views, add the folder and the error view(s).

That's it. Enjoy!

*NOTE: This repository will get merged into my WorldDomination.Web.Mv repo, later*

worlddomination.web.mvc.errorhandling's People

Contributors

phillip-haydon avatar purekrome avatar rjdudley avatar siimv avatar

Stargazers

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

Watchers

 avatar  avatar

worlddomination.web.mvc.errorhandling's Issues

Is there a way to route 404s generated by really long urls?

Hi, the default behavior of this package is working great! I have an issue where if someone enters a really long url by mistake, I get the standard IIS 404 error. Similar to this issue: http://stackoverflow.com/questions/14364281/trying-to-figure-out-a-strange-behavior-using-mvc-4-custom-error-pages-sometime

Is there a setting/way to tweak the setup so that I can add something like a catchall route and forward it to the fake error controller?

Hope this makes sense.

Thanks!

DL

NullReferenceException when HttpContext.Current.Error is null

I'm getting a NullReferenceException appearing when HttpContext.Current.Error is null. It only seems to happen for me when I do a request to a Web-Api controller that requires authentication, and the user hasn't yet authenticated via forms auth. Adding in a check for null values on currentError appears to resolve the problem and Web-Api then returns the correct 401 response.

CustomErrorHandlingModule.cs#L98

I'll try to submit a pull request after I work out how to use git.

_ViewStart.cshtml should be used for error view layout

Per this StackOverflow answer, my understanding is that my error views (404.cshtml, etc) should pick up the standard _ViewStart.cshtml and thus be rendered within my _Layout.cshtml like all my other views, but this is not working.

If I add the contents of _ViewStart.cshtml to my error view manually, I do get my error view rendered within my _Layout.cshtml as expected:

@model WorldDomination.Web.Mvc.ErrorViewModel

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@{
    ViewBag.Title = "401";
}

<h2>401</h2>

Looking at the error views in the sample project, I see they are written as full HTML documents, but this goes against the rest of the Asp.Net MVC convention. Instead, error views should pick up _ViewStart.cshtml (if present).

Here is a suggested fix to CustomErrorHandlingModule.RenderCustomErrorView(). Pass in true instead of false for the runViewStartPages value:

var view = new RazorView(controllerContext, viewPath, null, true, null);

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.