【发布时间】:2020-05-12 13:41:07
【问题描述】:
我通过以下步骤创建了一个简单的 ASP.NET Core Web 应用程序:
创建了 ASP.NET core 项目的 Empty 模板:
添加了一个带有 index.html 页面的 wwwroot 文件夹。
Startup.cs 是非常默认的,只添加了一行:
app.UseDefaultFiles();
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace WebApplication1
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDefaultFiles();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
}
}
}
构建解决方案并将我的 IIS 网站指向 Web 项目的根目录:
我在通过 IIS 运行站点时看到一个空白页面(没有控制台错误,权限已经授予解决方案的根目录):
我期待 index.html 的输出出现在应用程序 URL 的根目录中。 ASP.NET 核心项目是否需要做任何特殊操作才能使其通过 IIS 运行?
我也想通过在 Visual Studio 中为该给定站点附加 IIS 进程来进行调试?
你能分享我在那里缺少的东西吗?
同样的步骤似乎也适用于 ASP.NET 框架。我不想在 VS 上执行 Run 命令并在 localhost 上运行站点,我的目标是使用 IIS/ 使用有效 url 运行站点,以便我可以通过将进程附加到 Visual Studio 解决方案来直接调试。
【问题讨论】:
标签: c# asp.net asp.net-core iis