c# - 为什么 .Net Core 3.1 项目在发布到个人托管服务器(不是 IIS 和 Azure)时不起作用?
问题描述
我在 .Net Core 框架上开发了一个 CMS 项目,我想将它发布到我自己的服务器上,但不知何故我做不到。
我将尝试逐步解释该过程。我去项目详情:
首先,我在文件夹上发布项目,然后使用 FileZilla 上传到我的网站。
我的发布资料:
在这个地方,我尝试了 runtime:x64 和 deployment: framework-dependent,但我没有从它们中得到任何结果。我可以通过图像中的配置以这种方式显示。
请求 ID:|fb17a78-4b085bb85c5b93d5。
选择Self-Contained的原因是要上传合适的.Net Core Runtime,让项目在要安装的服务器上运行。
为了提供更多详细信息,其他代码块如下:
我的 .csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>aspnet-***CMS-**-**-**-**-**</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
</ItemGroup
</Project>
启动.cs:
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
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.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddControllersWithViews();
services.AddRazorPages();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
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.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
}
程序.cs:
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "data source=.\\;initial catalog=***;integrated security=True;multipleactiveresultsets=True;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
启动设置.json:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:62525",
"sslPort": 44323
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"***CMS": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
在本节中,我尝试使用开发而不是环境,但无论如何都没有工作。
我要感谢大家的回答和解决方案。
解决方案
推荐阅读
- python - HTTPSConnectionPool(host='xx.xx.xx.xx', port=443): url 超出最大重试次数
- azure - Azure 机器人服务/无法创建 Web 应用程序机器人/不支持位置
- javascript - 离子服务后找不到模块(webpack)/hot/emitter @angular-devkit/build-angular - Ionic 4
- opencv - 彩色滤光片 openCV
- c# - ASP dotnet core 中授权类和处理程序的标准是什么
- javascript - 加密和节点 10 中的未知消息摘要
- r - parse_block 中的错误(g[-1]、g[1]、params.src):重复标签 'unnamed-chunk-1
- javascript - 使用 Object.create() 从现有对象创建对象
- r - 使用 tabPanel UI 重置绘图
- php - 如何在 Laravel 5.7 中使用第三方 api 实现后备身份验证检查?