Commit ea342164 authored by Dmytro Bogatov's avatar Dmytro Bogatov 💕

Merge branch '38-upgrade-to-asp-core-2-0' into 'master'

Resolve "Upgrade to ASP Core 2.0"

Closes #38

See merge request dbogatov/status-site!21
parents fb3be3de 45423962
Pipeline #1212 passed with stages
in 11 minutes and 16 seconds
......@@ -56,3 +56,7 @@ debug
# Debian build artifacts
debian/build
test/appsettings.*
*lock.json
......@@ -9,7 +9,7 @@ before_script:
## BUILD
build-docs:
image: dbogatov/docker-containers:mkdocs-latest
image: dbogatov/docker-images:mk-docs-latest
stage: build
script:
- ./build.sh -f build-docs
......@@ -35,7 +35,7 @@ build-ping:
- docker
build-app:
image: dbogatov/docker-containers:dotnet-core-latest
image: dbogatov/docker-images:net-core-latest
stage: build
script:
- export ASPNETCORE_ENVIRONMENT="Production"
......@@ -53,24 +53,25 @@ build-app:
unit-test-app:
stage: test
image: microsoft/dotnet:1.1.1-sdk
image: microsoft/dotnet:2.0.3-sdk
script:
- printf "{\"Version\":{\"GitHash\":\"%s\"}}" $CI_BUILD_REF > src/version.json
- cd test
- dotnet restore
- dotnet build
- ./test.sh | tee tests.out
- "cat tests.out | grep 'Failed: 0.'"
- "cat tests.out | grep 'Test Run Successful.'"
tags:
- docker
tidy-app:
stage: test
image: dbogatov/docker-containers:dotnet-core-latest
image: dbogatov/docker-images:net-core-latest
dependencies:
- build-app
before_script:
- export ASPNETCORE_ENVIRONMENT="Staging"
- cd src/web/bin/release/netcoreapp1.1/publish/
- cd src/web/bin/release/netcoreapp2.0/publish/
- dotnet web.dll > /dev/null &
- sleep 15
script:
......@@ -81,12 +82,12 @@ tidy-app:
blc-app:
stage: test
image: dbogatov/docker-containers:dotnet-core-latest
image: dbogatov/docker-images:net-core-latest
dependencies:
- build-app
before_script:
- export ASPNETCORE_ENVIRONMENT="Staging"
- cd src/web/bin/release/netcoreapp1.1/publish/
- cd src/web/bin/release/netcoreapp2.0/publish/
- dotnet web.dll > /dev/null &
- sleep 15
script:
......@@ -96,7 +97,7 @@ blc-app:
blc-docs:
stage: test
image: dbogatov/docker-containers:jekyll-latest
image: dbogatov/docker-images:blc-latest
dependencies:
- build-docs
before_script:
......@@ -130,7 +131,7 @@ release-app-docs:
release-debian:
stage: release
image: dbogatov/docker-containers:debian-latest
image: dbogatov/docker-images:debian-latest
script:
- ./build.sh -f build-debian-package
artifacts:
......
......@@ -14,7 +14,7 @@
"request": "launch",
"preLaunchTask": "build-web",
"justMyCode": false,
"program": "${workspaceRoot}/src/web/bin/Debug/netcoreapp1.1/web.dll",
"program": "${workspaceRoot}/src/web/bin/Debug/netcoreapp2.0/web.dll",
"args": [],
"cwd": "${workspaceRoot}/src/web",
"externalConsole": false,
......@@ -27,7 +27,7 @@
"request": "launch",
"preLaunchTask": "build-daemons",
"justMyCode": false,
"program": "${workspaceRoot}/src/daemons/bin/Debug/netcoreapp1.1/daemons.dll",
"program": "${workspaceRoot}/src/daemons/bin/Debug/netcoreapp2.0/daemons.dll",
"args": [],
"cwd": "${workspaceRoot}/src/daemons",
"externalConsole": false,
......@@ -40,7 +40,7 @@
"request": "launch",
"preLaunchTask": "build-test",
"justMyCode": false,
"program": "${workspaceRoot}/test/bin/Debug/netcoreapp1.1/test.dll",
"program": "${workspaceRoot}/test/bin/Debug/netcoreapp2.0/test.dll",
"args": [],
"cwd": "${workspaceRoot}/test",
"externalConsole": false,
......
......@@ -9,7 +9,9 @@ strict: true
copyright: Copyright © 2017 Dmytro Bogatov
# Documentation and theme
theme_dir: material
theme:
name: 'material'
custom_dir: 'material'
# Options
extra:
......
......@@ -15,11 +15,7 @@ install-node-tools () {
echo "Installing node modules... Requires Yarn or MPM"
if hash yarn 2>/dev/null; then
yarn --ignore-engines > /dev/null
else
npm install > /dev/null
fi
yarn --ignore-engines > /dev/null
}
clean-doc-folder () {
......
FROM dbogatov/docker-containers:nginx-latest
FROM dbogatov/docker-images:nginx-latest
MAINTAINER Dmytro Bogatov dmytro@dbogatov.org
......
FROM microsoft/dotnet:1.1.1-runtime
FROM microsoft/dotnet:2.0.3-runtime
# Create directory for the app source code
WORKDIR /srv
# Copy the binary
COPY bin/release/netcoreapp1.1/publish/ /srv
COPY bin/release/netcoreapp2.0/publish/ /srv
ENTRYPOINT /bin/bash -c "dotnet daemons.dll"
......@@ -54,6 +54,8 @@ namespace StatusMonitor.Daemons.Services
public async Task<DataPoint> GenerateDemoDataAsync(Metrics type, string source, DateTime? timestamp = null)
{
var metric = await _metricService.GetOrCreateMetricAsync(type, source);
_context.Attach(metric);
// Using plain new Random() will result in the same number if called multiple times in short time period
var random = new Random(
......
......@@ -287,6 +287,12 @@ namespace StatusMonitor.Daemons.Services
.GetRequiredService<IHealthService>()
.ProduceHealthReportAsync();
// May happen in test environment
if (report.Metric != null)
{
context.Attach(report.Metric);
}
await context.HealthReports.AddAsync(report);
await context.SaveChangesAsync();
}
......@@ -353,6 +359,18 @@ namespace StatusMonitor.Daemons.Services
// Wait completion of all tasks
var pingDataPoints = await Task.WhenAll(tasks.ToArray());
pingDataPoints
.ToList()
.ForEach(
ping => {
// May happen in test environment
if (ping.Metric != null)
{
context.Attach(ping.Metric);
}
}
);
await context.PingDataPoints.AddRangeAsync(pingDataPoints);
await context.SaveChangesAsync();
......
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../shared/shared.csproj">
<Name>shared</Name>
</ProjectReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Npgsql" Version="3.1.9" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
<ProjectReference Include="../shared/shared.csproj" Name="shared" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0-*" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="2.0.0-*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Include="CommonMark.NET" Version="0.14.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Tools" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.6.38-alpha" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="1.1.0" />
<PackageReference Include="MailKit" Version="1.16.0" />
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="1.2.0" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="*" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="*" />
</ItemGroup>
<ItemGroup>
<AppSettings Include="../appsettings*.*"/>
......
......@@ -38,22 +38,14 @@ namespace StatusMonitor.Shared.Extensions
services
.AddEntityFrameworkSqlite()
.AddDbContext<DataContext>(
b => b.UseSqlite("Data Source=../../../../../development.db")
b => b.UseSqlite("Data Source=../development.db")
);
}
else // Testing and Staging
{
services
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<DataContext>(
b => b
.UseInMemoryDatabase()
.UseInternalServiceProvider(
new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider()
)
);
.AddDbContext<DataContext>(b => b.UseInMemoryDatabase("main-db"));
}
services.AddTransient<IDataContext, DataContext>();
......
......@@ -37,6 +37,7 @@ namespace StatusMonitor.Shared.Models
void RemoveRange(params object[] entities);
EntityEntry Remove(object entity);
EntityEntry Entry(object entity);
EntityEntry Attach(object entity);
}
/// <summary>
......
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputType>Library</OutputType>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Npgsql" Version="3.1.9" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0-*" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="2.0.0-*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Include="CommonMark.NET" Version="0.14.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Tools" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.6.38-alpha" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="1.1.0" />
<PackageReference Include="MailKit" Version="1.16.0" />
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="1.2.0" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="*" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="*" />
</ItemGroup>
</Project>
......@@ -18,7 +18,9 @@ namespace StatusMonitor.Web.Controllers.Api
{
// Retrieve requested metric
var metric = await _metricService.GetOrCreateMetricAsync(Metrics.Compilation, model.Source);
_context.Attach(metric);
// Retrieve requested user action
var compilationStage =
await _context
......
......@@ -15,7 +15,9 @@ namespace StatusMonitor.Web.Controllers.Api
{
// Retrieve requested metric
var metric = await _metricService.GetOrCreateMetricAsync(Metrics.CpuLoad, model.Source);
_context.Attach(metric);
// Record data
await _context
.NumericDataPoints
......
......@@ -18,6 +18,8 @@ namespace StatusMonitor.Web.Controllers.Api
// Retrieve requested metric
var metric = await _metricService.GetOrCreateMetricAsync(Metrics.Log, model.Source);
_context.Attach(metric);
// Retrieve requested user action
var logSeverity =
await _context
......
......@@ -18,6 +18,8 @@ namespace StatusMonitor.Web.Controllers.Api
// Retrieve requested metric
var metric = await _metricService.GetOrCreateMetricAsync(Metrics.UserAction, model.Source);
_context.Attach(metric);
// Record data
await _context
.UserActionDataPoints
......
FROM microsoft/dotnet:1.1.1-runtime
FROM microsoft/dotnet:2.0.3-runtime
# Create directory for the app source code
WORKDIR /srv
# Copy the binary
COPY bin/release/netcoreapp1.1/publish/ /srv
COPY bin/release/netcoreapp2.0/publish/ /srv
# Expose the port and start the app
EXPOSE 5555
......
using System;
using System.IO;
using System.Threading;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using StatusMonitor.Shared.Extensions;
namespace StatusMonitor.Web
......@@ -10,7 +13,7 @@ namespace StatusMonitor.Web
/// This class contains the entry point for the application.
/// </summary>
public class Program
{
{
/// <summary>
/// The entry point.
/// This function is responsible for starting up the server object.
......@@ -22,7 +25,7 @@ namespace StatusMonitor.Web
public static int Main(string[] args)
{
int port = 5555;
if (args.Length != 0 && (!Int32.TryParse(args[0], out port) || port < 1024 || port > 65534))
if (args.Length != 0 && (!Int32.TryParse(args[0], out port) || port < 1024 || port > 65534))
{
ColoredConsole.WriteLine("Usage: dotnet web.dll [port | number 1024-65534]", ConsoleColor.Red);
return 1;
......@@ -42,14 +45,18 @@ namespace StatusMonitor.Web
{
try
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
var host = WebHost
.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging(
logging => {
logging.ClearProviders();
logging.AddFilter("Microsoft", LogLevel.None);
}
)
.UseUrls($"http://*:{port}")
.Build(); // Connection to the database happens in .Build()
.Build();
host.Run();
return 0;
......
......@@ -4,6 +4,8 @@ using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
......@@ -59,16 +61,17 @@ namespace StatusMonitor.Web.Services
new ClaimsIdentity(
new List<Claim> {
new Claim("UserId", "Admin"),
}, "Admin"
},
CookieAuthenticationDefaults.AuthenticationScheme
)
);
await _http.HttpContext.Authentication.SignInAsync("CookieMiddlewareInstance", principal);
await _http.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);
}
public async Task SignOutAsync()
{
await _http.HttpContext.Authentication.SignOutAsync("CookieMiddlewareInstance");
await _http.HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
}
}
}
......@@ -64,44 +64,19 @@ namespace StatusMonitor.Web
{
services.RegisterSharedServices(CurrentEnvironment, Configuration);
services.AddIdentity<User, IdentityRole>();
services.Configure<IdentityOptions>(options =>
{
// Cookie settings
options.Cookies.ApplicationCookie.AuthenticationScheme = "CookieMiddlewareInstance";
options.Cookies.ApplicationCookie.LoginPath = new PathString("/account/login");
options.Cookies.ApplicationCookie.AccessDeniedPath = new PathString("/account/login");
options.Cookies.ApplicationCookie.AutomaticAuthenticate = true;
options.Cookies.ApplicationCookie.AutomaticChallenge = true;
options.Cookies.ApplicationCookie.CookieName = "AUTHCOOKIE";
options.Cookies.ApplicationCookie.ExpireTimeSpan = new TimeSpan(1, 0, 0, 0);
options.Cookies.ApplicationCookie.CookieHttpOnly = true;
var cookie = options.Cookies.ApplicationCookie;
var events = cookie.Events;
cookie.Events = new CookieAuthenticationEvents
{
OnRedirectToAccessDenied = context =>
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(
CookieAuthenticationDefaults.AuthenticationScheme,
options =>
{
if (context.Request.Path.StartsWithSegments("/api"))
{
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return Task.CompletedTask;
}
return events.RedirectToAccessDenied(context);
},
OnRedirectToLogin = context =>
{
if (context.Request.Path.Value.Contains("/api"))
{
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
return Task.CompletedTask;
}
return events.RedirectToLogin(context);
options.LoginPath = "/Account/LogIn";;
options.AccessDeniedPath = new PathString("/account/login");
options.Cookie.Name = "AUTHCOOKIE";
options.ExpireTimeSpan = new TimeSpan(1, 0, 0, 0);
options.Cookie.HttpOnly = true;
}
};
});
);
services.AddMemoryCache();
services.AddSession();
......@@ -124,6 +99,7 @@ namespace StatusMonitor.Web
services.AddCors();
// Add application services.
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddTransient<IApiController, ApiController>();
services.AddTransient<HomeController>();
......@@ -155,6 +131,8 @@ namespace StatusMonitor.Web
Configuration.StringsFromArray("Logging:Exclude").ToArray()
);
app.UseAuthentication();
if (env.IsProduction())
{
app.UseExceptionHandler("/error"); // All serverside exceptions redirect to error page
......@@ -165,7 +143,7 @@ namespace StatusMonitor.Web
app.UseDatabaseErrorPage();
app.UseDeveloperExceptionPage(); // Print full stack trace
}
app.UseSession();
app.UseCors(builder => builder.WithOrigins("*"));
......@@ -173,8 +151,6 @@ namespace StatusMonitor.Web
app.UseDefaultFiles(); // in wwwroot folder, index.html is served when opening a directory
app.UseStaticFiles(); // make accessible and cache wwwroot files
app.UseIdentity();
// define routes
app.UseMvc(routes =>
{
......
......@@ -2,8 +2,12 @@
ViewData["Title"] = Model.Title;
}
@using StatusMonitor.Web.Services
@model StatusMonitor.Shared.Models.Entities.Metric
@inject IAuthService Auth
<div class="container">
<div class="block-header">
<h2>
......@@ -86,7 +90,7 @@
</div>
@if (Context.User.Identity.IsAuthenticated)
@if (Auth.IsAuthenticated())
{
<div class="col-md-12">
......
@using Microsoft.Extensions.Configuration
@using StatusMonitor.Web.Services
@inject IConfiguration Config
@inject IAuthService Auth
<!DOCTYPE html>
<!--[if IE 9 ]><html class="ie9"><![endif]-->
......@@ -44,7 +46,7 @@
<ul class="hi-menu">
@if (Context.User.Identity.IsAuthenticated)
@if (Auth.IsAuthenticated())
{
<li>
<a asp-controller="Admin" asp-action="Index" >
......@@ -108,7 +110,7 @@
<ul class="f-menu">
<li><a asp-controller="Home" asp-action="Index">Home</a></li>
@if (Context.User.Identity.IsAuthenticated)
@if (Auth.IsAuthenticated())
{
<li>
<a
......
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../shared/shared.csproj">
<Name>shared</Name>
</ProjectReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Npgsql" Version="3.1.9" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
<ProjectReference Include="../shared/shared.csproj" Name="shared" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0-*" />