mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Added handling of all missing routes with custom 404 page.
This commit is contained in:
parent
f472c4f5d7
commit
c98e6cbf8e
@ -8,6 +8,16 @@ namespace Teknik
|
||||
public static void RegisterRoutes(RouteCollection routes)
|
||||
{
|
||||
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
|
||||
|
||||
// Add this code to handle non-existing urls
|
||||
routes.MapRoute(
|
||||
name: "404-PageNotFound",
|
||||
// This will handle any non-existing urls
|
||||
url: "{*url}",
|
||||
// "Shared" is the name of your error controller, and "Error" is the action/page
|
||||
// that handles all your custom errors
|
||||
defaults: new { controller = "Default", action = "NotFound" }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,6 +91,21 @@ namespace Teknik
|
||||
return route;
|
||||
}
|
||||
|
||||
public static SubdomainRoute MapSubdomainRoute(this AreaRegistrationContext context, string name, List<string> subDomains, List<string> domains, string url, object defaults, object constraints, string[] namespaces)
|
||||
{
|
||||
SubdomainRoute route = new SubdomainRoute(
|
||||
subDomains,
|
||||
domains,
|
||||
url,
|
||||
new RouteValueDictionary(defaults),
|
||||
new RouteValueDictionary(constraints),
|
||||
new RouteValueDictionary(new { Area = context.AreaName, Namespaces = namespaces }),
|
||||
new MvcRouteHandler());
|
||||
|
||||
context.Routes.Add(name, route);
|
||||
return route;
|
||||
}
|
||||
|
||||
public static SubdomainRoute MapSubdomainRoute(this AreaRegistrationContext context, string name, List<string> subDomains, List<string> domains, string url, string area, object defaults)
|
||||
{
|
||||
SubdomainRoute route = new SubdomainRoute(
|
||||
|
@ -42,6 +42,17 @@ namespace Teknik.Areas.Home
|
||||
new[] { typeof(DefaultController).Namespace }
|
||||
);
|
||||
|
||||
// Register fallback for all bad requests
|
||||
context.MapSubdomainRoute(
|
||||
"Default.NotFound", // Route name
|
||||
new List<string>() { "*" }, // Subdomains
|
||||
new List<string>() { config.Host }, // domains
|
||||
"{url}", // URL with parameters
|
||||
new { controller = "Default", action = "NotFound" }, // Parameter defaults
|
||||
new { url = "{*url}" },
|
||||
new[] { typeof(DefaultController).Namespace }
|
||||
);
|
||||
|
||||
context.MapSubdomainRoute(
|
||||
"Home.Index", // Route name
|
||||
new List<string>() { "www", string.Empty }, // Subdomains
|
||||
|
@ -29,7 +29,7 @@
|
||||
<br />
|
||||
<div class="row text-center">
|
||||
<h2>
|
||||
Teknik is dedicated to the advancement of technology and ideas, and we provide these services to help those who try to innovate.
|
||||
We provide these services to help those who try to innovate.
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -65,6 +65,18 @@ namespace Teknik.Controllers
|
||||
string imageFile = Server.MapPath(Constants.LOGO_PATH);
|
||||
return File(imageFile, "image/svg+xml");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public ActionResult NotFound()
|
||||
{
|
||||
var errorController = new ErrorController();
|
||||
if (errorController != null)
|
||||
{
|
||||
return errorController.Http404(new Exception("Page Not Found"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
|
@ -37,11 +37,11 @@
|
||||
<forms domain=".teknik.io" protection="All" enableCrossAppRedirects="true" name="TeknikAuth" />
|
||||
</authentication>
|
||||
<compilation debug="true" targetFramework="4.6.2" />
|
||||
<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" executionTimeout="3600" />
|
||||
<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" executionTimeout="3600" relaxedUrlToFileSystemMapping="true" />
|
||||
<pages buffer="true" enableViewState="false" />
|
||||
</system.web>
|
||||
<system.webServer>
|
||||
<modules>
|
||||
<modules runAllManagedModulesForAllRequests="true">
|
||||
<remove name="FormsAuthentication" />
|
||||
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
|
||||
<add name="PerfModule" type="Teknik.Modules.PerformanceMonitorModule, Teknik" />
|
||||
|
Loading…
Reference in New Issue
Block a user