2016-12-09 4 views
0

У меня проблема с обслуживанием статического файла в ядре asp.net. Я действительно новичок в этом. Просто последовал за учебником из множественного числа и застрял здесь.UseStaticFiles() throws error "Connection failed"

Я добавил index.html в папку wwwroot и добавил зависимости для статического файла в Json, но все еще не работает. Любая помощь будет оценена по достоинству.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Threading.Tasks; 
using Microsoft.AspNetCore.Builder; 
using Microsoft.AspNetCore.Hosting; 
using Microsoft.AspNetCore.Http; 
using Microsoft.Extensions.DependencyInjection; 
using Microsoft.Extensions.Logging; 

namespace TheWorld 
{ 
    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, IHostingEnvironment env, ILoggerFactory loggerFactory) 
     { 
      app.UseStaticFiles(); 
      // app.Run(async (context) => 
      // { 
      //  await context.Response.WriteAsync("Hello World!"); 
      // }); 
     } 
    } 
} 

И это мой project.json

{ 
    "dependencies": { 
    "Microsoft.NETCore.App": { 
     "version": "1.0.1", 
     "type": "platform" 
    }, 
    "Microsoft.AspNetCore.Diagnostics": "1.0.0", 

    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", 
    "Microsoft.Extensions.Logging.Console": "1.0.0", 
    "Microsoft.AspNetCore.StaticFiles": "1.0.0" 
    }, 

    "tools": { 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" 
    }, 

    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": [ 
     "dotnet5.6", 
     "portable-net45+win8" 
     ] 
    } 
    }, 

    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "runtimeOptions": { 
    "configProperties": { 
     "System.GC.Server": true 
    } 
    }, 

    "publishOptions": { 
    "include": [ 
     "wwwroot", 
     "web.config" 
    ] 
    }, 

    "scripts": { 
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    } 
} 

ответ

0

Для того, чтобы ваш веб-приложение, чтобы служить страницу по умолчанию пользователю не полностью определить URI, вызовите метод UseDefaultFiles расширения от Startup.Configure в следующим образом.

public void Configure(IApplicationBuilder app) 
{ 
    app.UseDefaultFiles(); 
    app.UseStaticFiles(); 
} 

UseDefaultFiles должна вызываться перед UseStaticFiles служить файл по умолчанию.

Код: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files#serving-default-files

+0

спасибо. Это действительно работает. –