Большие правки
У меня есть веб-приложение C 2.2 ASP.Net core 2.2 (было 2.1 в оригинальном вопросе), которое я пытаюсь развернуть на сервере IIS 8.5. Развертывание происходит. Я могу достичь маршрута по умолчанию, и действия на стороне сервера работают для этого маршрута. Ни один из других определенных маршрутов не работает, хотя. На сервере IIS, если я пытаюсь выполнить действие MyInitialController
, отличное от Index
, я получаю страницу ошибки:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Detailed Error Information:
Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0x80070003
Config Error Cannot read configuration file
Config File \\?\E:\www\myapp.company.com\Content\MyInitialController\web.config
Requested URL https://myapp.company.com:443/MyInitialController/Item?device=MY_WIDGET
Physical Path E:\www\myapp.company.com\Content\MyInitialController\Calendar
Logon Method Not yet determined
Logon User Not yet determined
Config Source:
-1:
0:
More Information:
This error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error.
View more information »
Обратите внимание на значение Config File
. На сервере IIS нет папки с именем «MyInitialController». Корневой каталог папки сайта IIS: \? \ E: \ www \ myapp.company.com \ Content. Я понятия не имею, что заставляет его думать, что web.config должен быть на один уровень ниже в папке, которая не существует.
startup.cs
:
using System;
using CalendarMyInitialControllers.Models.Commodities;
using CalendarMyInitialControllers.Models.UserTracking;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace CalendarMyInitialControllers {
public class Startup {
public Startup(IHostingEnvironment env) {
var builder = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) {
services.Configure<CookiePolicyOptions>(options => {
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// Add memory cache services
services.AddMemoryCache();
services.AddSession(options => {
options.IdleTimeout = TimeSpan.FromMinutes(600); //You can set Time
});
}
// 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");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseExceptionHandler("/MyInitialController/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseSession();
app.UseMvc(routes => {
routes.MapRoute(
"default",
"{controller=MyInitialController}/{action=Index}"
);
routes.MapRoute(
"Calendar",
"MyInitialController/Item/{device}"
);
});
}
}
}
launchSettings:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:52839",
"sslPort": 44375
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"applicationUrl": "https://localhost:44375;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"CalendarReservations": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:44375;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
AppSettings:
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}