我正在使用Visual Studio 2015将我的ASP.NET Core应用程序发布到IIS 7.5。我想要做的就是在wwwroot中查看一个普通的default.htm页面。当我使用VS的IIS Express时,一切都正常,但是当我将其发布到IIS 7.5并将物理路径指向Visual Studio在发布时创建的wwwroot文件夹时,我什么也看不到,只有一个空白屏幕(404)。奇怪的是,当我从startup.cs的Configure方法中运行默认的app.run方法时,它完美地工作:
我已经确认我已经下载了httpPlatformHandler v1.2,当我从VS发布时,我针对DNX版本dnx-clr-winx86.1.0.0-rc1-update1进行目标设置,并勾选以下两个选项(在发布之前删除所有现有文件和将源文件编译为NuGet包)。它在IIS Express中运行得很好。当我尝试使用IIS 7.5时,它开始变得奇怪。
有什么建议吗?
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
然而,当我注释掉这部分代码,使用app.UseDefaultFiles()和app.UseStaticFiles()时,我什么也看不到。以下是我的Startup.cs文件:
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 http://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)
{
app.UseIISPlatformHandler();
//app.UseDirectoryBrowser();
//app.UseDefaultFiles();
//app.UseStaticFiles();
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
这是我的web.config文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
</system.webServer>
</configuration>
以下是我的project.json文件:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
我已经确认我已经下载了httpPlatformHandler v1.2,当我从VS发布时,我针对DNX版本dnx-clr-winx86.1.0.0-rc1-update1进行目标设置,并勾选以下两个选项(在发布之前删除所有现有文件和将源文件编译为NuGet包)。它在IIS Express中运行得很好。当我尝试使用IIS 7.5时,它开始变得奇怪。
有什么建议吗?
index.html
文件吗?如果你没有配置路由,并且没有使用app.Run
返回任何内容,那么导航到站点的根目录将会导致404错误,因为...嗯...找不到文件。 - Will Ray