2017-03-04 7 views
0

正常に機能している一部のコントローラでASP.NET Coreアプリケーションを作成しました。ASP.NET Coreアプリケーションのルートからの特定の応答を返します

ルーティングシステムはhttps://something.com/api/controllerのように構成されています。

ただし、私はを常に使用しています。ウェブアプリケーションを常にアクティブに保ち、アイドル状態では一時停止しないようにするには、常にAzureのオプションを有効にしてください。

問題は、アドレスhttps://something.comとAzureのpingが私のアプリ、5分ごとにあり、私のアプリケーションの洞察報告書に記録され404エラーが発生して戻ってきます。

私は自分のアプリケーションのルートに対して行われたリクエストを処理し、代わりに200のHTTP結果を返すことができます。ここで

が私のスタートアップクラスです:

public class Startup 
{ 
    public Startup(IHostingEnvironment env) 
    { 
     var builder = new ConfigurationBuilder() 
      .SetBasePath(env.ContentRootPath) 
      .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) 
      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 
      .AddEnvironmentVariables(); 
     Configuration = builder.Build(); 
    } 

    private IConfigurationRoot Configuration { get; } 

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

     services.AddSingleton<ICachingService>(e => new CachingService(Configuration["Redis:ConnectionString"])); 

     var loggingService = new LoggingService(Configuration["ApplicationInsights:InstrumentationKey"]); 
     services.AddSingleton(typeof(ILoggingService), loggingService); 
    } 

    // 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) 
    { 
     loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
     loggerFactory.AddDebug(); 

     app.UseMvc(); 
    } 
} 

答えて

1

さてさて、それは実際にはめちゃくちゃ簡単です:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
    { 
     app.UseMvc(); 
     app.Run(async context => 
     { 
      await context.Response.WriteAsync("API"); // returns a 200 with "API" as content. 
     }); 
    } 
+0

これは非常にシンプルなソリューションである、それが効果的にマッチしますキャッチすべてのルートでありますそれ以外のものがなければ – juunas

+0

/pathに制限することができます。 – Tratcher

関連する問題