ASP.NET5.0添加html文件(ASP.NET5.0 Add html file)
我有一个html文件index.html,我想与我的asp.net5项目链接。
我试图在wwwroot中添加index.html,当我开始调试时,我转到localhost:port / index.html,它没有显示任何内容。
有人可以链接到文档或解释如何做到这一点?
PS:我使用visual-studio。
配置代码:
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseIISPlatformHandler();
app.Run(async (context) =>
{
await context.Response.WriteAsync("test");
});
}
I got a html file index.html that i want to link with my asp.net5 project.
I have tried to add the index.html in wwwroot and when I start the debug I go to localhost:port/index.html and it shows me nothing.
Can some one link to a documentation or explain how to do it?
PS: I use visual-studio.
Config code:
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseIISPlatformHandler();
app.Run(async (context) =>
{
await context.Response.WriteAsync("test");
});
}
原文:https://stackoverflow.com/questions/37216793
更新时间:2019-11-10 06:32
最满意答案
您必须告诉应用程序您要使用静态文件。 例如,您不需要在Web Api 2.0服务器中使用它。 因此,默认情况下不会添加。 在你的Startup.cs中添加app.UseStaticFiles(); 到Configure方法。
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc();
}
You have to tell the app that you want to use static files. You wouldn't need it in a Web Api 2.0 server for instance. So, this is not added by default. In your Startup.cs add app.UseStaticFiles(); to the Configure method.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc();
}
相关问答
您必须告诉应用程序您要使用静态文件。 例如,您不需要在Web Api 2.0服务器中使用它。 因此,默认情况下不会添加。 在你的Startup.cs中添加app.UseStaticFiles(); 到Configure方法。 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseIISPlatformHandler(
...
我的工作在我身边。请试试这个: @{
ViewBag.Title = "Home Page";
Layout = null;
}
在你的代码中只需添加属性: protected void Page_Load(object sender, EventArgs e)
{
html_tag.Attributes.Add("xmlns:og","http://ogp.
...
确保你在没有调试的情况下启动项目(VS中的Ctrl + F5而不是F5)。 即时编译不适用于附加的调试器 Make sure you start the project without debugging (Ctrl + F5 in VS instead of F5). The compile on the fly doesn't work with a debugger attached
您的代码应如下所示: