2017-12-15 3 views
0

私はcli "ng build --prod"でビルドして、私が提供したいasp.netコアプロジェクトのwwwrootディレクトリとのサイト。 aspプロジェクトには私が使用しているMVCコントローラがないので、考慮する必要はありません。asp.netコア2プロジェクトのルートにサービスを提供する

Iデフォルトファイルと静的ファイルを使用するようにアプリケーションを設定します。これは、サーバールート(この場合はlocalhost:5000 =>(デリバリー)index.html)に移動すると、角度のあるアプリケーションになります。そこから私はアプリケーションを使用してルートを動作させることができます。

しかし、手動でリンクするときは(例えば、http://localhost:5000/quality-test-listと入力してください)、私は何も書かれていない白いページしか得ません。

私の推測では、サーバー側のルーティングはこれを禁止しています。 私は標準の "dotnet new angular"プロジェクトファイルを見ましたが、わかりません。

私のスタートアップファイル:あなたのconfigureセクションで

public class Startup 
{ 
    public Startup(IConfiguration configuration) 
    { 
     Configuration = configuration; 
    } 

    public IConfiguration Configuration { get; } 

    // This method gets called by the runtime. Use this method to add services to the container. 
    public void ConfigureServices(IServiceCollection services) 
    { 
     services.AddMvc(); 
    } 

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 
    public void Configure(IApplicationBuilder app, IHostingEnvironment env) 
    { 
     if (env.IsDevelopment()) 
     { 
      app.UseDeveloperExceptionPage(); 
     } 
     app.UseDefaultFiles(); 
     app.UseStaticFiles(); 

    } 
} 
+0

試み[このチュートリアル](httpsにすべての404を構成するためにapp.useメソッドを使用します://メディア。 com/@ elmeerr/set-up-angular-2-net-core-project-angle-cli-and-visual-studio-2015-61206cc502b5) –

+0

@ElmerDantasこのリンクは無効です。 –

+0

もう一度確認してください。あなたはそれの終わりにあなたが望むものを見つけるでしょう。秘密はあなたのindex.htmlに "見つからない"ルートをリダイレクトするだけです。 –

答えて

0

、以下のごindex.html

app.Use(async (context, next) => { 
       await next(); 
       if(context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value)){ 
        context.Request.Path = "/index.html"; 
        await next(); 
       } 
    }) 
    .UseDefaultFiles(new DefaultFilesOptions { DefaultFilesName = new List<string>{ "index.html" } }) 
    .UseStaticFiles(new StaticFilesOptions 
        { 
         FileProvider = new PhysicalFileProvider(
          Path.Combine(Directory.GetCurrentDiretory(), "@wwwroot")), 
          RequestPath = new PathString("") 
    }) 
    .UseMvc(); 
関連する問題