2016-02-22 190 views
3

我努力让我的ASP.Net核心1(asp.net 5/MVC 6)应用程序在我的web服务器上的IIS内运行。我跟着向导,做服务器上的以下在IIS上部署ASP.Net核心1应用程序(404错误)

  • 通过get.asp.net安装ASP.Net 5
  • 安装HttpPlatformHandler 1.2

我检查,我可以运行在服务器上的dnx和编译的位是64位,并且应用程序池是“无托管代码”并且以64位运行。

当我尝试,我可以通过运行web.cmd并导航到http://localhost:5000(或其他端口),然而运行在Web服务器上应用程序和设置应用程序的缺省Web站点中的应用程序,浏览到它(例如,http://localhost/MyMVC6App)我收到一个404错误。我检查了物理路径指向/ MyMVC6App/wwwroot。我还检查了webserver/handlers部分已解锁。

我也创建了一个香草ASP.Net 5 /核心1应用程序,并在2个不同的服务器上得到相同的404错误!

这里是我的配置方法:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
     { 
      loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
      loggerFactory.AddDebug(); 

      app.UseApplicationInsightsRequestTelemetry(); 

      if (env.IsDevelopment()) 
      { 
       app.UseBrowserLink(); 
       app.UseDeveloperExceptionPage(); 
      } 
      else 
      { 
       app.UseExceptionHandler("/Home/Error"); 
      } 

      app.UseIISPlatformHandler(); 

      app.UseApplicationInsightsExceptionTelemetry(); 

      app.UseStaticFiles(); 

      app.UseMvc(routes => 
      { 
       routes.MapRoute(
        name: "default", 
        template: "{controller=Home}/{action=Index}/{id?}"); 
      }); 
     } 

任何想法?

+1

我也刚刚发现如果我创建一个新网站(而不是Web应用程序)并将其作为唯一的Web应用程序托管,我可以运行该应用程序。然而,因为我有其他的网络应用程序(MVC 5及以下),我不能这样做,因为我需要在不同的端口上运行新的网站。 – Calanus

+0

当您尝试访问URL时,您可以确认IIS AppPool启动dnx.exe吗?如果不是,那么这意味着问题出现在web.config文件中的HttpPlatform配置中。 web.config中的路径使用我认为的相对路径。如果它正在启动dnx.exe,那么应该在httpPlatform配置文件中启用stdoutLogEnabled =“true”后立即死亡,以找出原因。 –

+0

info:Microsoft.Extensions.DependencyInjection.DataProtectionServices [0] 用户配置文件可用。使用'C:\ Windows \ system32 \ config \ systemprofile \ AppData \ Local \ ASP.NET \ DataProtection-Keys'作为密钥存储库,并使用Windows DPAPI来加密静态密钥。 主机环境:生产 现在正在监听:http:// localhost:8465 应用程序已启动。按下Ctrl + C关闭。 info:Microsoft.AspNet.Hosting.Internal.HostingEngine [1] 请求开始HTTP/1.1 GET http:// localhost/Extranet info:Microsoft.AspNet.Hosting.Internal.HostingEngine [2] 请求在0.0656ms完成404 – Calanus

回答

1

解决这个问题的最简单方法是,如果您的静态文件托管在ASPNET Core应用程序之外,则将添加IIS应用程序名称作为您的MVC路径的基础。

另一种方法是添加一个简单的中间件类去除IIS应用程序的名称,并使请求看起来对其下面的任何模块都透明。我还没有测试下面的代码,但是:

using System.Threading.Tasks; 
using Microsoft.AspNet.Builder; 
using Microsoft.AspNet.Http; 

namespace MyMVC6App 
{ 
    // You may need to install the Microsoft.AspNet.Http.Abstractions package into your project 
    public class RemoveIISAppNameMiddleware 
    { 
     private readonly RequestDelegate _next; 

     public RemoveIISAppNameMiddleware(RequestDelegate next) 
     { 
      _next = next; 
     } 

     public Task Invoke(HttpContext httpContext) 
     { 
      var newRequestPath = new PathString(); 
      var requestPathToIgnore = new PathString("/MyMVC6App"); 

      if (httpContext.Request.Path.StartsWithSegments(requestPathToIgnore)) 
      { 
       httpContext.Request.Path.StartsWithSegments(requestPathToIgnore, out newRequestPath); 
       httpContext.Request.Path = newRequestPath; 
      } 
      return _next(httpContext); 
     } 
    } 

    // Extension method used to add the middleware to the HTTP request pipeline. 
    public static class RemoveIISAppNameMiddlewareExtensions 
    { 
     public static IApplicationBuilder UseRemoveIISAppName(this IApplicationBuilder builder) 
     { 
      return builder.UseMiddleware<RemoveIISAppNameMiddleware>(); 
     } 
    } 
} 

,然后在app.UseIISPlatformHandler()后您的配置方法,你能叫app.UseRemoveIISAppName()。在这种情况下,你不需要在MVC路由中有任何额外的路径。

+0

我已经尝试了上述方法,并在http://www.damirscorner.com/blog/posts/20160214-DeployingAspNetCoreRc1ApplicationToIis.html中列出的方法都使我得到一击该页面,但所有的CSS和脚本链接不再起作用。我试图使用Fiddler来处理它,并找到一个可以工作的url,但我目前没有任何运气。 – Calanus

相关问题