refact
This commit is contained in:
@ -3,13 +3,27 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using IdentityServer4.Services;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using nuget_host.Models;
|
using nuget_host.Models;
|
||||||
|
|
||||||
namespace nuget_host.Controllers
|
namespace nuget_host.Controllers
|
||||||
{
|
{
|
||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
|
private readonly IIdentityServerInteractionService _interaction;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
IHostingEnvironment _environment;
|
||||||
|
|
||||||
|
public HomeController(IIdentityServerInteractionService interaction, Microsoft.AspNetCore.Hosting.IHostingEnvironment environment, ILogger<HomeController> logger)
|
||||||
|
{
|
||||||
|
_interaction = interaction;
|
||||||
|
_environment = environment;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
@ -37,9 +51,28 @@ namespace nuget_host.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IActionResult Error()
|
/// <summary>
|
||||||
|
/// Shows the error page
|
||||||
|
/// </summary>
|
||||||
|
public async Task<IActionResult> Error(string errorId)
|
||||||
{
|
{
|
||||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
var vm = new ErrorViewModel();
|
||||||
|
|
||||||
|
// retrieve error details from identityserver
|
||||||
|
var message = await _interaction.GetErrorContextAsync(errorId);
|
||||||
|
if (message != null)
|
||||||
|
{
|
||||||
|
vm.Error = message;
|
||||||
|
|
||||||
|
if (!_environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
// only show in development
|
||||||
|
message.ErrorDescription = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return View("Error", vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using IdentityServer4.Models;
|
||||||
|
|
||||||
namespace nuget_host.Models
|
namespace nuget_host.Models
|
||||||
{
|
{
|
||||||
@ -7,5 +8,18 @@ namespace nuget_host.Models
|
|||||||
public string RequestId { get; set; }
|
public string RequestId { get; set; }
|
||||||
|
|
||||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||||
|
|
||||||
|
|
||||||
|
public ErrorViewModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorViewModel(string error)
|
||||||
|
{
|
||||||
|
Error = new ErrorMessage { Error = error };
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorMessage Error { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,22 +0,0 @@
|
|||||||
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
|
|
||||||
|
|
||||||
|
|
||||||
using IdentityServer4.Models;
|
|
||||||
|
|
||||||
namespace IdentityServerHost.Quickstart.UI
|
|
||||||
{
|
|
||||||
public class ErrorViewModel
|
|
||||||
{
|
|
||||||
public ErrorViewModel()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public ErrorViewModel(string error)
|
|
||||||
{
|
|
||||||
Error = new ErrorMessage { Error = error };
|
|
||||||
}
|
|
||||||
|
|
||||||
public ErrorMessage Error { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
|
|
||||||
|
|
||||||
|
|
||||||
using IdentityServer4.Services;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IdentityServerHost.Quickstart.UI
|
|
||||||
{
|
|
||||||
[SecurityHeaders]
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class HomeController : Controller
|
|
||||||
{
|
|
||||||
private readonly IIdentityServerInteractionService _interaction;
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
IHostingEnvironment _environment;
|
|
||||||
|
|
||||||
public HomeController(IIdentityServerInteractionService interaction, Microsoft.AspNetCore.Hosting.IHostingEnvironment environment, ILogger<HomeController> logger)
|
|
||||||
{
|
|
||||||
_interaction = interaction;
|
|
||||||
_environment = environment;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult Index()
|
|
||||||
{
|
|
||||||
if (_environment.IsDevelopment())
|
|
||||||
{
|
|
||||||
// only show in development
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInformation("Homepage is disabled in production. Returning 404.");
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Shows the error page
|
|
||||||
/// </summary>
|
|
||||||
public async Task<IActionResult> Error(string errorId)
|
|
||||||
{
|
|
||||||
var vm = new ErrorViewModel();
|
|
||||||
|
|
||||||
// retrieve error details from identityserver
|
|
||||||
var message = await _interaction.GetErrorContextAsync(errorId);
|
|
||||||
if (message != null)
|
|
||||||
{
|
|
||||||
vm.Error = message;
|
|
||||||
|
|
||||||
if (!_environment.IsDevelopment())
|
|
||||||
{
|
|
||||||
// only show in development
|
|
||||||
message.ErrorDescription = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return View("Error", vm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user