Skip to content

Commit 4dd08d7

Browse files
committed
Introduced basic error response pages
1 parent 9d877b0 commit 4dd08d7

File tree

8 files changed

+70
-41
lines changed

8 files changed

+70
-41
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project OnTopicSample OnTopic Site
5+
\=============================================================================================================================*/
6+
using Ignia.Topics.ViewModels;
7+
using Ignia.Topics.Web.Mvc.Controllers;
8+
9+
namespace Ignia.Topics.Web.Mvc.Host.Controllers {
10+
11+
/*============================================================================================================================
12+
| CLASS: ERROR CONTROLLER
13+
\---------------------------------------------------------------------------------------------------------------------------*/
14+
/// <summary>
15+
/// Provides access to the views associated with 400 and 500 error results.
16+
/// </summary>
17+
public class ErrorController : ErrorControllerBase<PageTopicViewModel> {
18+
19+
} // Class
20+
} // Namespace

Ignia.Topics.Web.Mvc.Host/Ignia.Topics.Web.Mvc.Host.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
</ItemGroup>
106106
<ItemGroup>
107107
<Compile Include="App_Start\RouteConfig.cs" />
108+
<Compile Include="Controllers\ErrorController.cs" />
108109
<Compile Include="Controllers\LayoutController.cs" />
109110
<Compile Include="Global.asax.cs">
110111
<DependentUpon>Global.asax</DependentUpon>
@@ -129,6 +130,9 @@
129130
<Content Include="Views\_ViewStart.cshtml" />
130131
<Content Include="Views\Layout\Menu.cshtml" />
131132
<Content Include="Views\Layout\PageLevelNavigation.cshtml" />
133+
<Content Include="Views\Error\Error.cshtml" />
134+
<Content Include="Views\Error\InternalServer.cshtml" />
135+
<Content Include="Views\Error\NotFound.cshtml" />
132136
<None Include="Web.Debug.config">
133137
<DependentUpon>Web.config</DependentUpon>
134138
</None>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@model PageTopicViewModel
2+
3+
@{
4+
Layout = "~/Views/Layout/_Layout.cshtml";
5+
ViewBag.Title = "Unhandled Error";
6+
}
7+
8+
<h1>Error</h1>
9+
<p>Error Message</p>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@model PageTopicViewModel
2+
3+
@{
4+
Layout = "~/Views/Layout/_Layout.cshtml";
5+
ViewBag.Title = "Internal Server Error";
6+
}
7+
8+
<h1>Internal Server Error</h1>
9+
<p>Error Message</p>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@model PageTopicViewModel
2+
3+
@{
4+
Layout = "~/Views/Layout/_Layout.cshtml";
5+
ViewBag.Title = "Page Not Found";
6+
}
7+
8+
<h1>Page Not Found</h1>
9+
<p>Error Message</p>

Ignia.Topics.Web.Mvc.Host/Views/Layout/PageLevelNavigation.cshtml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
@model NavigationViewModel<NavigationTopicViewModel>
22

3-
<h2>PageLevelNavigation</h2>
4-
<ul>
5-
@foreach (var topic in Model.NavigationRoot.Children) {
6-
<li><a href="@topic.WebPath">@(topic.ShortTitle?? topic.Title)</a></li>
7-
}
8-
</ul>
3+
@if (Model.NavigationRoot != null) {
4+
5+
<h2>PageLevelNavigation</h2>
6+
<ul>
7+
@foreach (var topic in Model.NavigationRoot.Children) {
8+
<li><a href="@topic.WebPath">@(topic.ShortTitle?? topic.Title)</a></li>
9+
}
10+
</ul>
11+
12+
}
913

1014
<!--
1115
Content Type: NavigationViewModel<NavigationTopicViewModel>

Ignia.Topics.Web.Mvc.Host/Web.Release.config

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,15 @@
33
<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->
44

55
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
6-
<!--
7-
In the example below, the "SetAttributes" transform will change the value of
8-
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
9-
finds an attribute "name" that has a value of "MyDB".
10-
11-
<connectionStrings>
12-
<add name="MyDB"
13-
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
14-
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
15-
</connectionStrings>
16-
-->
176
<system.web>
187
<compilation xdt:Transform="RemoveAttributes(debug)" />
19-
<!--
20-
In the example below, the "Replace" transform will replace the entire
21-
<customErrors> section of your web.config file.
22-
Note that because there is only one customErrors section under the
23-
<system.web> node, there is no need to use the "xdt:Locator" attribute.
24-
25-
<customErrors defaultRedirect="GenericError.htm"
26-
mode="RemoteOnly" xdt:Transform="Replace">
27-
<error statusCode="500" redirect="InternalError.htm"/>
28-
</customErrors>
29-
-->
308
</system.web>
9+
<system.webServer>
10+
<httpErrors errorMode="Custom" existingResponse="Replace" xdt:Transform="Insert">
11+
<remove statusCode="404" />
12+
<remove statusCode="500" />
13+
<error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" />
14+
<error statusCode="500" responseMode="ExecuteURL" path="/Error/InternalServer" />
15+
</httpErrors>
16+
</system.webServer>
3117
</configuration>

Ignia.Topics.Web.Mvc.Host/Web.config

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
-->
66
<configuration>
77

8-
<appSettings>
9-
<add key="webpages:Version" value="3.0.0.0" />
10-
<add key="webpages:Enabled" value="false" />
11-
<add key="ClientValidationEnabled" value="true" />
12-
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
13-
</appSettings>
14-
158
<connectionStrings configSource="Configuration\ConnectionStrings.config"></connectionStrings>
169

1710
<system.web>
@@ -33,10 +26,6 @@
3326
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
3427
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
3528
</dependentAssembly>
36-
<dependentAssembly>
37-
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
38-
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
39-
</dependentAssembly>
4029
<dependentAssembly>
4130
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
4231
<bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
@@ -51,8 +40,7 @@
5140
<system.codedom>
5241
<compilers>
5342
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
54-
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
5543
</compilers>
5644
</system.codedom>
5745

58-
</configuration>
46+
</configuration>

0 commit comments

Comments
 (0)