通过 IIS 部署网站:无法访问站点 [英] Website Deployment via IIS : Can't access site
问题描述
在服务器上安装 .NET Hosting Bundle 后,我使用 IIS 创建了一个站点.但是,我无法通过 url 使用浏览器访问该站点.Google Chrome 出现错误 DNS_PROBE_FINISHED_NXDOMAIN
.
I created a site using IIS, after installing .NET Hosting Bundle on server.
However, I am not able to access the site with the browser via url. Google Chrome gave the error DNS_PROBE_FINISHED_NXDOMAIN
.
因此,我添加了对 localhost:443
的绑定,并从服务器计算机访问了该站点.但是浏览器中出现错误:HTTP 502.5
.从日志中可以看出,IIS 似乎读取了 http 请求.
So,I added a binding to localhost:443
, and accessed the site from the server computer. However an error appeared in the browser: HTTP 502.5
. It appears that the IIS reads the http requests, as may be seen in the log.
这是我的 web.config 文件:
Here is my web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".MVF2.exe" stdoutLogEnabled="false" stdoutLogFile=".logsstdout" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 99f7528d-8954-427a-86a5-7124668717df-->
Program.cs 文件是:
The Program.cs file is:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace MVF2
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Listen(IPAddress.Loopback, 443, listenOptions =>
{
listenOptions.UseHttps("mycertificate.crt");
});
});
}
}
这里我显示的是IIS站点的日志:
Here I show the log of the IIS site:
#Software: Microsoft Internet Information Services 8.5
#Version: 1.0
#Date: 2020-01-30 14:35:38
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2020-01-30 14:35:38 ::1 GET / - 443 - ::1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - 502 5 2147500037 859
2020-01-30 14:44:14 ::1 GET / - 443 - ::1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - 502 5 2147500037 1078
接下来我展示我的 Startup.cs:
Next I show my Startup.cs:
namespace MyProgram
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public AppFeatures features { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<idDbContext>(options =>
{
var connectionString = Configuration.GetConnectionString("idDataContext");
options.UseSqlServer(connectionString);
});
services.AddIdentity<AppUser, IdentityRole>(opts =>
{
opts.Password.RequiredLength = 6;
opts.Password.RequireNonAlphanumeric = false;
opts.Password.RequireLowercase = false;
opts.Password.RequireUppercase = false;
opts.Password.RequireDigit = false;
}).AddEntityFrameworkStores<idDbContext>()
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(opts =>
{
opts.LoginPath = "/Login/Login";
opts.AccessDeniedPath = "/Login/AccessDenied";
});
services.AddDbContext<fmDataContext>(options =>
{
var connectionString = Configuration.GetConnectionString("fmDataContext");
options.UseSqlServer(connectionString);
});
services.AddTransient<AppFeatures>(x => (features = new AppFeatures
{
DevelopmentEnvironment = Configuration.GetValue<bool>("AppFeatures:DevelopmentEnvironment"),
SqlServerCredentials = Configuration.GetConnectionString("fmDataContext")
}));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddMemoryCache();
services.AddSession();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
AppFeatures features)
{
app.UseExceptionHandler("/Error.html");
if (features.DevelopmentEnvironment)
{
app.UseDeveloperExceptionPage();
}
app.UseAuthentication();
app.Use(async (context, next) =>
{
if (context.Request.Path.Value.Contains("error"))
throw new Exception("ERRO!");
await next();
});
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute("Default",
"{controller=Home}/{action=Index}/{id?}");
});
app.UseFileServer();
idDbContext.CreateAdminAccount(app.ApplicationServices, Configuration).Wait();
}
}
}
你能帮我吗?
推荐答案
@salli 我通过 https://localhost 访问了该站点:443/ 因为我已经添加了这个绑定.但是,除了证书中的错误(证书颁发给 *.my.me 之类的东西)之外,我在启动应用程序时也有错误.这里我展示了网站的日志:
@salli I accessed the site via https://localhost:443/ since I had added this binding. However, besides the error in the certificate (the certificate is issued to something like *.my.me), I have an error in the launching of the app. Here I show the log of the site:
#Software: Microsoft Internet Information Services 8.5
#Version: 1.0
#Date: 2020-01-30 14:35:38
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2020-01-30 14:35:38 ::1 GET / - 443 - ::1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - 502 5 2147500037 859
2020-01-30 14:44:14 ::1 GET / - 443 - ::1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - 502 5 2147500037 1078
接下来我展示我的 Startup.cs:
Next I show my Startup.cs:
namespace MyProgram
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public AppFeatures features { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<idDbContext>(options =>
{
var connectionString = Configuration.GetConnectionString("idDataContext");
options.UseSqlServer(connectionString);
});
services.AddIdentity<AppUser, IdentityRole>(opts =>
{
opts.Password.RequiredLength = 6;
opts.Password.RequireNonAlphanumeric = false;
opts.Password.RequireLowercase = false;
opts.Password.RequireUppercase = false;
opts.Password.RequireDigit = false;
}).AddEntityFrameworkStores<idDbContext>()
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(opts =>
{
opts.LoginPath = "/Login/Login";
opts.AccessDeniedPath = "/Login/AccessDenied";
});
services.AddDbContext<fmDataContext>(options =>
{
var connectionString = Configuration.GetConnectionString("fmDataContext");
options.UseSqlServer(connectionString);
});
services.AddTransient<AppFeatures>(x => (features = new AppFeatures
{
DevelopmentEnvironment = Configuration.GetValue<bool>("AppFeatures:DevelopmentEnvironment"),
SqlServerCredentials = Configuration.GetConnectionString("fmDataContext")
}));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddMemoryCache();
services.AddSession();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
AppFeatures features)
{
app.UseExceptionHandler("/Error.html");
if (features.DevelopmentEnvironment)
{
app.UseDeveloperExceptionPage();
}
app.UseAuthentication();
app.Use(async (context, next) =>
{
if (context.Request.Path.Value.Contains("error"))
throw new Exception("ERRO!");
await next();
});
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute("Default",
"{controller=Home}/{action=Index}/{id?}");
});
app.UseFileServer();
idDbContext.CreateAdminAccount(app.ApplicationServices, Configuration).Wait();
}
}
}
你能帮我吗?
编辑
我解决了这个问题,允许登录我的应用程序 web.config
如下:
I solved this problem enabling logging in my app web.config
as following:
<aspNetCore processPath=".MVF2.exe" stdoutLogEnabled="true" stdoutLogFile=".logsstdout" />
然后我能够在 .logs
目录中的日志文件中看到错误.
Then I was able to see the error in the log files in .logs
directory.
这篇关于通过 IIS 部署网站:无法访问站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!