1. Web.Config
<customErrors mode="On | RemoteOnly"
defaultRedirect="~/Views/Shared/Error.cshtml">
<error statusCode="403"
redirect="~/Views/Shared/UnauthorizedAccess.cshtml" />
<error statusCode="404"
redirect="~/Views/Shared/FileNotFound.cshtml" />
</customErrors>
OR
<customErrors mode="On" defaultRedirect="~/Home/Error"/>
===========================================
2. App_start/Filter.config
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new CustomHandleErrorAttribute());
filters.Add(new AuthorizeAttribute());
filters.Add(new ClearCacheAttribute());
// filters.Add(new CheckUserCookieAttribute());
filters.Add(new RequireHttpsAttribute());
filters.Add(new SecuredConnection());
}
}
===============================================================
3. Global.asax
protected override void Application_Start(object sender, EventArgs e)
{
base.Application_Start(sender, e);
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
if (!HttpContext.Current.IsDebuggingEnabled)
BundleTable.EnableOptimizations = true;
}
==============================
~/Home/Error"/
==============================
public ActionResult Error()
{
Exception exception = Server.GetLastError();
System.Diagnostics.Debug.WriteLine(exception);
return View();
}
~/Home/Error.CSHTML
==============================
@model System.Web.Mvc.HandleErrorInfo
@{
ViewBag.Title = "Error From Config";
}
@Html.ActionLink("Back to Home Page", "Index", new { Controller = "Home" }, new { @class = "regislnk" })
<hgroup class="title">
<h1 class="error">Error.</h1>
<h2 class="error">An error occurred while processing your request.</h2>
@if (Model != null)
{
<p>
<h4 class="error">Exception : @Model.Exception.Message<br />
</h4>
</p>
<pre>
@Model.Exception.StackTrace.ToString()
</pre>
}
</hgroup>
Thursday, June 21, 2018
Custom Error Page in ASP.NET MVC
Subscribe to:
Post Comments (Atom)
javascript Filter/index off
var family = [{"name":"Jack", "age": 26}, {"name":"Jill", "age"...
-
A3+C3 VLOOKUP(G3,$A$3:$B$10,2) sum Product Quantity Count Result 1 Mobile 2 1 Mobile 3 Keyboard 3 2 Mobile 6 TV 1 3 ...
-
EF CORE CLI > dotnet ef database update MyFirstMigration. Scaffold-DbContext Command Use Scaffold-DbContext to create a model based ...
No comments:
Post a Comment