我的应用程序正在运行ASP.NET Core RC2,我对状态代码和异常处理程序中间件如何工作感到困惑.
我的应用程序配置了以下中间件.
app.UseStatusCodePagesWithReExecute("/Error/Status/{0}");
app.UseExceptionHandler("/Error/ServerError");
Run Code Online (Sandbox Code Playgroud)
控制器处理它应返回的视图:
[HttpGet]
public IActionResult Status(int id)
{
switch (id)
{
case 404:
return View("404");
case 400:
return View("400");
case 500:
return View("500");
default:
return View("501");
}
}
[HttpGet]
public IActionResult ServerError()
{
return View();
}
Run Code Online (Sandbox Code Playgroud)
当我导航到一个未知的URL时,它将404 page从Status动作返回预期的.
当我导航到抛出异常的操作时,它将导航到状态操作/Error/ServerError而不是导航500 page.
public IActionResult ThrowException()
{
throw new Exception();
}
Run Code Online (Sandbox Code Playgroud)
如果我导航到返回的操作,StatusCodeResult(500);将返回500 pageStatus操作.
[HttpGet]
public IActionResult Error500()
{
return new StatusCodeResult(500);
}
Run Code Online (Sandbox Code Playgroud)
令我困惑的是,控制台显示两个结果都返回500 (Internal Server …
我创建了一个运行Ubuntu 16.04的新VM并运行该命令.dotnet new -t web这将创建一个新的基本MVC Web模板.接下来我运行了应用程序,连接成功.
之后我修改了nginx.conf以使用SSL
server {
listen 443 http2 ssl default;
ssl_certificate /etc/ssl/certs/testCert.crt;
ssl_certificate_key /etc/ssl/certs/testCert.key;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
location / {
proxy_pass http://localhost:5000;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
}
}
Run Code Online (Sandbox Code Playgroud)
再次运行应用程序,它在HTTPS下运行,没有错误.
然后我在Startup.cs中配置了MVC服务来强制执行HTTPS.
services.AddMvc(config =>
{
config.Filters.Add(new RequireHttpsAttribute());
}); …Run Code Online (Sandbox Code Playgroud) 在我的wwwroot文件夹中,我有两个名为lib和的子文件夹lib_bower.我的lib_bower文件夹在我的.bowerrc文件中设置如下:
{
"directory": "wwwroot/lib_bower"
}
Run Code Online (Sandbox Code Playgroud)
当我恢复时,bower packages我离开了这个:
如果找不到文件,我想在构建时将整个dist文件夹移动bootstrap到我的lib文件夹中.我怎样才能做到这一点?
我最近安装了 Visual Studio 2017。我迁移了在 Visual Studio 2015 中创建的现有项目。它被迁移没有任何错误。但是当我构建解决方案时,我收到 100 多个错误说明Package [Microsoft.AspNetCore...] is not compatible with [netcoreapp...]
有 100 多个项目是这样列出的。我尝试重命名
删除
修复、卸载和重新安装 Visual Studio 2017 中的sdk值时的值。但它们都不起作用。global.jsonsdkglobal.json
我不知道在哪里添加net451在imports作为解释这里,因为project.json文件被迁移时删除。
同一个项目在 Visual Studio 2015 中运行良好。所有问题都是在迁移到 Visual Studio 2017 后开始的。
请让我知道如何修复此错误。