我正在使用Visual Studio 2015将我的ASP.NET核心应用程序发布到IIS 7.5。我要做的就是在我的wwwroot中查看正常的default.htm页面。当我使用VS的IIS Express时,一切正常,但是当我发布到IIS 7.5并指向Visual Studio在发布时创建的wwwroot文件夹的物理路径时,我只得到一个空白屏幕(404)。有什么奇怪的,当我在startup.cs的Configure方法中运行默认的app.run方法时,它运行得很完美:
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以及勾选2个选项下面(在发布之前删除所有现有文件,并将源文件编译成NuGet包)。它在IIS Express中运行良好。当我尝试使用IIS 7.5时,它开始变得时髦。
有什么建议吗?
答案 0 :(得分:3)
编辑 - 我解决了
出于某种原因,您必须在Configure方法之前使用Configure1方法。在Configure方法中,您必须使用app.map()。此外,我注意到您必须在IIS中创建一个新站点并将该应用程序发布到该文件夹,同时设置wwwroot的物理路径。站点名称和app.map()名称必须匹配。见下文:
public Startup(IHostingEnvironment env)
{
}
// 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)
{
services.AddMvc();
}
public void Configure1(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseIISPlatformHandler();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.Map("/appRoot", (app1) => this.Configure1(app1, env, loggerFactory));
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
现在,我遇到了我的WebAPI搞乱的问题。希望这有帮助!