Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use these steps:</p> <pre><code>// in Global.asax.cs: protected void Application_Error(object sender, EventArgs e) { var ex = Server.GetLastError().GetBaseException(); Server.ClearError(); var routeData = new RouteData(); routeData.Values.Add("controller", "Error"); routeData.Values.Add("action", "Index"); if (ex.GetType() == typeof(HttpException)) { var httpException = (HttpException)ex; var code = httpException.GetHttpCode(); routeData.Values.Add("status", code); } else { routeData.Values.Add("status", 500); } routeData.Values.Add("error", ex); IController errorController = new Kavand.Web.Controllers.ErrorController(); errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData)); } protected void Application_EndRequest(object sender, EventArgs e) { if (Context.Response.StatusCode == 401) { // this is important, because the 401 is not an error by default!!! throw new HttpException(401, "You are not authorised"); } } </code></pre> <p>AND:</p> <pre><code>// in Error Controller: public class ErrorController : Controller { public ActionResult Index(int status, Exception error) { Response.StatusCode = status; return View(status); } protected override void Dispose(bool disposing) { base.Dispose(disposing); } } </code></pre> <p>AND the index view in Error folder:</p> <pre><code>@* in ~/Views/Error/Index.cshtml: *@ @model Int32 @{ Layout = null; } &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Kavand | Error&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; There was an error with your request. The error is:&lt;br /&gt; &lt;p style=" color: Red;"&gt; @switch (Model) { case 401: { &lt;span&gt;Your message goes here...&lt;/span&gt; } break; case 403: { &lt;span&gt;Your message goes here...&lt;/span&gt; } break; case 404: { &lt;span&gt;Your message goes here...&lt;/span&gt; } break; case 500: { &lt;span&gt;Your message goes here...&lt;/span&gt; } break; //and more cases for more error-codes... default: { &lt;span&gt;Unknown error!!!&lt;/span&gt; } break; } &lt;/p&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>AND -the final step:</p> <pre><code>&lt;!-- in web.config: --&gt; &lt;customErrors mode="Off"/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload