Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Mono FastCgi成功响应200次,但未找到Nginx http响应404_Asp.net_Linux_Nginx_Mono_Fastcgi - Fatal编程技术网

Asp.net Mono FastCgi成功响应200次,但未找到Nginx http响应404

Asp.net Mono FastCgi成功响应200次,但未找到Nginx http响应404,asp.net,linux,nginx,mono,fastcgi,Asp.net,Linux,Nginx,Mono,Fastcgi,我正在尝试使用Mono/Nginx/Fastcgi将一个C#asp.net项目移植到Ubuntu,在一些API请求中,我看到Nginx返回404 http响应,而我期望的是200。该应用程序可以在Windows服务器上与IIS配合使用,因此我非常感谢您能为调试这种不一致的行为提供帮助 我正在使用:mono 4.5 nightly、nginx 1.9、fastcgi-mono-server4和Net4.5项目 使用xbuild'mysolution.sln,我的代码可以很好地编译,然后运行 fas

我正在尝试使用Mono/Nginx/Fastcgi将一个C#asp.net项目移植到Ubuntu,在一些API请求中,我看到Nginx返回404 http响应,而我期望的是200。该应用程序可以在Windows服务器上与IIS配合使用,因此我非常感谢您能为调试这种不一致的行为提供帮助

我正在使用:mono 4.5 nightly、nginx 1.9、fastcgi-mono-server4和Net4.5项目

使用
xbuild'mysolution.sln
,我的代码可以很好地编译,然后运行

fastcgi-mono-server4/applications=/:/var/www/html/{包含my/bin}/socket的文件夹=tcp:127.0.0.1:9000/printlog=True/verbose=True&
打开我的mono fastcgi服务器,然后打开我的nginx服务器
服务nginx重启

但在运行时,当前端请求碰到我的任何API时,包括以下API

[HttpGet]
[Authorize]
[Route("UserRoles")]
public IHttpActionResult GetUserRoles(string userId)
{
    var userRoles = _repo.GetUserRoles(userId);
    return Ok(userRoles);
}
它有时返回404错误,而不是200成功

通过Charles跟踪我的http请求/响应显示nginx正在发送404 not found响应,因此我认为问题在于API

但是,添加带有添加日志记录的自定义MessageHandler表明API正在接收请求、处理请求,然后返回一个成功响应。似乎是在MessageHandler和nginx服务器之间的某个地方,没有找到从200到404的响应消息

由于在Charles中重放相同的API请求会返回200响应,因此在多个请求期间Mono中似乎存在一些资源约束问题

我已经尝试在nginx和fastcgi中打开调试,以获得更有用的日志记录:
error\u log/var/log/nginx/error.log debug在nginx.conf中,并在运行Fastcgi时使用
loglevels=All

但是没有看到任何有用的东西

nginx配置/etc/nginx/sites enabled/default

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html/RM.WebAPI;
    error_log /var/log/nginx/error.log debug;
    rewrite_log on;

    location / {
            try_files $uri $uri/ @proxy;
    }

    location @proxy {
            if ($request_method = 'OPTIONS') {
                    add_header 'Access-Control-Allow-Origin' $http_origin always;
                    add_header 'Access-Control-Allow-Credentials' 'true'; 
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

                    return 204;
            }

            include /etc/nginx/fastcgi_params;
            fastcgi_next_upstream http_404; #invalid_header http_500;
            fastcgi_keep_conn off;
            autoindex on;

            fastcgi_pass 127.0.0.1:9000;
    }
}
我的自定义MessageHandler MonomMessageHandler.cs

public class MonoMessageHandler : DelegatingHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        var response = base.SendAsync(request, cancellationToken);

        Console.WriteLine("Returning response {0}:{3} for request {1}\n Content:{2}", response.Result.ToString(), request.RequestUri.ToString(), response.Result.Content.ToString(), response.Result.IsSuccessStatusCode);
        return response;
    }
}
公共类MonMessageHandler:DelegatingHandler
{
受保护的覆盖任务SendAsync(HttpRequestMessage请求,CancellationToken CancellationToken)
{
var response=base.sendaync(请求、取消令牌);
Console.WriteLine(“返回请求{1}的响应{0}:{3}\n内容:{2}”、response.Result.ToString()、request.RequestUri.ToString()、response.Result.Content.ToString()、response.Result.issessStatusCode);
返回响应;
}
}
更新:添加自定义异常处理程序后,我在MessageHandler中开始出现以下错误

 System.Runtime.ExceptionServices.ExceptionDispatchInfo
 Response:System.Web.Http.Results.ExceptionResult
 Exception:System.NullReferenceException: Object reference not set to an instance of an object
  at RM.WebAPI.MonoPatchingDelegatingHandler.SendAsync     (System.Net.Http.HttpRequestMessage request, CancellationToken cancellationToken) <0x40f18640 + 0x0019d> in <filename unknown>:0 
  at System.Net.Http.DelegatingHandler.SendAsync (System.Net.Http.HttpRequestMessage request, CancellationToken cancellationToken) <0x40f18600 + 0x0002b> in <filename unknown>:0 
  at System.Web.Http.HttpServer.<>n__FabricatedMethod9 (System.Net.Http.HttpRequestMessage , CancellationToken ) <0x40f185d0 + 0x0001b> in <filename unknown>:0 
  at System.Web.Http.HttpServer+<SendAsync>d__0.MoveNext () <0x40efbbb0 + 0x0042f> in <filename unknown>:0 
System.Runtime.ExceptionServices.ExceptionDispatchInfo
响应:System.Web.Http.Results.ExceptionResult
异常:System.NullReferenceException:对象引用未设置为对象的实例
位于0中的RM.WebAPI.MonoPatchingDelegatingHandler.SendAsync(System.Net.Http.HttpRequestMessage请求,CancellationToken CancellationToken)处
在0中的System.Net.Http.DelegatingHandler.SendAsync(System.Net.Http.HttpRequestMessage请求,CancellationToken CancellationToken)处
在System.Web.Http.HttpServer.n_u中,在以下位置制作了方法9(System.Net.Http.HttpRequestMessage,CancellationToken):0
在System.Web.Http.HttpServer+d__0.MoveNext()中:0