2016-04-06 8 views
-1

をコントローラに周りのルートへの仕事の呼び出しをrequest.pathを構築しながらKrestelがエラーを投げ、私は次の例外受け取る:MVC 6 - 、

System.ArgumentException 

    at Microsoft.AspNet.Http.PathString..ctor(String value) 
    at Microsoft.AspNet.Http.Internal.DefaultHttpRequest.get_Path() 
    at Microsoft.AspNet.StaticFiles.Helpers.TryMatchPath(HttpContext context, PathString matchUrl, Boolean forDirectory, PathString& subpath) 

the Request METHOD is GET 
HTTP Version HTTP/1.1 
Content-Type : application/x-www-form-urlencoded 
Accept-Encoding : {gzip} 

は、任意の助けいただければ幸いです。

public Startup(IHostingEnvironment env) 
{ 
    // Set up configuration sources. 
    var builder = new ConfigurationBuilder() 
     .AddJsonFile("appsettings.json") 
     .AddJsonFile("XDCRInfo.json") 
     .AddEnvironmentVariables(); 
    Configuration = builder.Build(); 
} 

public void ConfigureServices(IServiceCollection services) 
{ 
    var policy = new Microsoft.AspNet.Cors.Infrastructure.CorsPolicy(); 

    policy.Headers.Add("*"); 
    policy.Methods.Add("*"); 
    policy.Origins.Add("*"); 
    policy.SupportsCredentials = true; 

    services.Configure<XDCRSettings>(Configuration.GetSection("XDCRSettings")); 

    // Adding Cors 
    services.AddCors(options => 
    { 
     options.AddPolicy("CrossOrigin", policy); 
    }); 

    // Add framework services. 
    services.AddMvc();    

    services.Configure<MvcOptions>(options => 
    { 
     options.RespectBrowserAcceptHeader = true; 
    }); 
} 

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
{ 
    app.UseExceptionHandler("/Home/Error"); 

    app.Use(next => async context => 
     // Keep the original stream in a separate 
     // variable to restore it later if necessary. 
     var stream = context.Request.Body; 

     // Optimization: don't buffer the request if 
     // there was no stream or if it is rewindable. 
     if (stream == Stream.Null || stream.CanSeek) 
     { 
      await next(context); 
      return; 
     } 

     try 
     { 
      using (var buffer = new MemoryStream()) 
      { 
       // Copy the request stream to the memory stream. 
       await stream.CopyToAsync(buffer); 

       // Rewind the memory stream. 
       buffer.Position = 0L; 

       // Replace the request stream by the memory stream. 
       context.Request.Body = buffer; 

       // Invoke the rest of the pipeline. 
       await next(context); 
      } 
     } 
     catch (System.ArgumentException ex) 
     { 
      var Frame = (Microsoft.AspNet.Server.Kestrel.Http.Frame)context.Features; 

      Console.WriteLine(Frame.RequestUri); 
     } 
     finally 
     { 
      // Restore the original stream. 
      context.Request.Body = stream; 
      Console.WriteLine(context.Request); 
     } 
    }); 

    app.UseCors("CrossOrigin"); 

    app.UseMvc(); 
} 

App.useエラーを捕捉するために使用しました。それ以外の場合、私はその要求を見ることができませんでした。

+0

少なくともあなたのコードを表示してください。 – SubliemeSiem

+0

パブリックスタートアップ(IHostingEnvironment env) { //設定ソースを設定します。 var builder = new ConfigurationBuilder() .AddJsonFile( "appsettings.json") .AddJsonFile( "XDCRInfo.json") .AddEnvironmentVariables(); 構成= builder.Build(); } –

答えて

0

私は考え出しました。 AbsoluteURLがパスにある場合、Kestrelは中断します。それを動作させるには、これは回避策です。

 app.Use(next => async context => { 

        // get the frame from kestrel and then but the path by removing the hostname 
        var Frame = (Microsoft.AspNet.Server.Kestrel.Http.Frame)context.Features; 

        var newpath = Frame.RequestUri.Replace("http://" + context.Request.Host.Value, ""); 
        context.Request.Path = newpath; 

        // Invoke the rest of the pipeline. 
        await next(context); 

     }); 
関連する問題