From c5c247ecc30bde8ac9dba4ca5fa2d7347c385a6f Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Sun, 13 Oct 2019 20:44:09 +0300 Subject: [PATCH] Code cleanup --- .../MyWebsite/Controllers/HomeController.cs | 37 +------- MyWebsite/MyWebsite/Startup.cs | 18 +--- MyWebsite/MyWebsite/Views/Home/About.cshtml | 7 -- MyWebsite/MyWebsite/Views/Home/Contact.cshtml | 17 ---- MyWebsite/MyWebsite/Views/Home/Index.cshtml | 94 ------------------- MyWebsite/MyWebsite/Views/Home/Privacy.cshtml | 6 -- MyWebsite/MyWebsite/Views/Shared/Error.cshtml | 31 +++--- .../Views/{About => Shared}/Index.cshtml | 0 .../Views/Shared/_CookieConsentPartial.cshtml | 41 -------- .../Shared/_ValidationScriptsPartial.cshtml | 18 ---- 10 files changed, 26 insertions(+), 243 deletions(-) delete mode 100644 MyWebsite/MyWebsite/Views/Home/About.cshtml delete mode 100644 MyWebsite/MyWebsite/Views/Home/Contact.cshtml delete mode 100644 MyWebsite/MyWebsite/Views/Home/Index.cshtml delete mode 100644 MyWebsite/MyWebsite/Views/Home/Privacy.cshtml rename MyWebsite/MyWebsite/Views/{About => Shared}/Index.cshtml (100%) delete mode 100644 MyWebsite/MyWebsite/Views/Shared/_CookieConsentPartial.cshtml delete mode 100644 MyWebsite/MyWebsite/Views/Shared/_ValidationScriptsPartial.cshtml diff --git a/MyWebsite/MyWebsite/Controllers/HomeController.cs b/MyWebsite/MyWebsite/Controllers/HomeController.cs index 4472646..ee883f6 100644 --- a/MyWebsite/MyWebsite/Controllers/HomeController.cs +++ b/MyWebsite/MyWebsite/Controllers/HomeController.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; +using System.Diagnostics; using Microsoft.AspNetCore.Mvc; using MyWebsite.Models; @@ -10,34 +6,11 @@ namespace MyWebsite.Controllers { public class HomeController : Controller { - public IActionResult Index() - { - return View(); - } - - public IActionResult About() - { - ViewData["Message"] = "Your application description page."; - - return View(); - } - - public IActionResult Contact() - { - ViewData["Message"] = "Your contact page."; - - return View(); - } - - public IActionResult Privacy() - { - return View(); - } + public IActionResult Index() => + View(); [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } + public IActionResult Error() => + View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } } diff --git a/MyWebsite/MyWebsite/Startup.cs b/MyWebsite/MyWebsite/Startup.cs index 3d180de..1429462 100644 --- a/MyWebsite/MyWebsite/Startup.cs +++ b/MyWebsite/MyWebsite/Startup.cs @@ -1,11 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -38,15 +33,8 @@ namespace MyWebsite // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else - { - app.UseExceptionHandler("/Home/Error"); - app.UseHsts(); - } + app.UseExceptionHandler("/Home/Error"); + app.UseHsts(); app.UseHttpsRedirection(); app.UseStaticFiles(); diff --git a/MyWebsite/MyWebsite/Views/Home/About.cshtml b/MyWebsite/MyWebsite/Views/Home/About.cshtml deleted file mode 100644 index 3674e37..0000000 --- a/MyWebsite/MyWebsite/Views/Home/About.cshtml +++ /dev/null @@ -1,7 +0,0 @@ -@{ - ViewData["Title"] = "About"; -} -

@ViewData["Title"]

-

@ViewData["Message"]

- -

Use this area to provide additional information.

diff --git a/MyWebsite/MyWebsite/Views/Home/Contact.cshtml b/MyWebsite/MyWebsite/Views/Home/Contact.cshtml deleted file mode 100644 index a11a186..0000000 --- a/MyWebsite/MyWebsite/Views/Home/Contact.cshtml +++ /dev/null @@ -1,17 +0,0 @@ -@{ - ViewData["Title"] = "Contact"; -} -

@ViewData["Title"]

-

@ViewData["Message"]

- -
- One Microsoft Way
- Redmond, WA 98052-6399
- P: - 425.555.0100 -
- -
- Support: Support@example.com
- Marketing: Marketing@example.com -
diff --git a/MyWebsite/MyWebsite/Views/Home/Index.cshtml b/MyWebsite/MyWebsite/Views/Home/Index.cshtml deleted file mode 100644 index f42d2a0..0000000 --- a/MyWebsite/MyWebsite/Views/Home/Index.cshtml +++ /dev/null @@ -1,94 +0,0 @@ -@{ - ViewData["Title"] = "Home Page"; -} - - - -
-
-

Application uses

-
    -
  • Sample pages using ASP.NET Core MVC
  • -
  • Theming using Bootstrap
  • -
-
- - - -
diff --git a/MyWebsite/MyWebsite/Views/Home/Privacy.cshtml b/MyWebsite/MyWebsite/Views/Home/Privacy.cshtml deleted file mode 100644 index 7bd3861..0000000 --- a/MyWebsite/MyWebsite/Views/Home/Privacy.cshtml +++ /dev/null @@ -1,6 +0,0 @@ -@{ - ViewData["Title"] = "Privacy Policy"; -} -

@ViewData["Title"]

- -

Use this page to detail your site's privacy policy.

diff --git a/MyWebsite/MyWebsite/Views/Shared/Error.cshtml b/MyWebsite/MyWebsite/Views/Shared/Error.cshtml index ec2ea6b..7ac479c 100644 --- a/MyWebsite/MyWebsite/Views/Shared/Error.cshtml +++ b/MyWebsite/MyWebsite/Views/Shared/Error.cshtml @@ -3,20 +3,25 @@ ViewData["Title"] = "Error"; } -

Error.

-

An error occurred while processing your request.

+
+

Error.

+

An error occurred while processing your request.

+
-@if (Model.ShowRequestId) -{ +
+ @if (Model.ShowRequestId) + { +

+ Request ID: @Model.RequestId +

+ } + +

Development Mode

- Request ID: @Model.RequestId + Swapping to Development environment will display more detailed information about the error that occurred.

-} +

+ Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. +

+
-

Development Mode

-

- Swapping to Development environment will display more detailed information about the error that occurred. -

-

- Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. -

diff --git a/MyWebsite/MyWebsite/Views/About/Index.cshtml b/MyWebsite/MyWebsite/Views/Shared/Index.cshtml similarity index 100% rename from MyWebsite/MyWebsite/Views/About/Index.cshtml rename to MyWebsite/MyWebsite/Views/Shared/Index.cshtml diff --git a/MyWebsite/MyWebsite/Views/Shared/_CookieConsentPartial.cshtml b/MyWebsite/MyWebsite/Views/Shared/_CookieConsentPartial.cshtml deleted file mode 100644 index bbfbb09..0000000 --- a/MyWebsite/MyWebsite/Views/Shared/_CookieConsentPartial.cshtml +++ /dev/null @@ -1,41 +0,0 @@ -@using Microsoft.AspNetCore.Http.Features - -@{ - var consentFeature = Context.Features.Get(); - var showBanner = !consentFeature?.CanTrack ?? false; - var cookieString = consentFeature?.CreateConsentCookie(); -} - -@if (showBanner) -{ - - -} \ No newline at end of file diff --git a/MyWebsite/MyWebsite/Views/Shared/_ValidationScriptsPartial.cshtml b/MyWebsite/MyWebsite/Views/Shared/_ValidationScriptsPartial.cshtml deleted file mode 100644 index 2a9241f..0000000 --- a/MyWebsite/MyWebsite/Views/Shared/_ValidationScriptsPartial.cshtml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - -