Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.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/1/asp.net/29.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
C# WebAPI没有';t在控制器上维护窗体身份验证_C#_Asp.net_Api_Controller - Fatal编程技术网

C# WebAPI没有';t在控制器上维护窗体身份验证

C# WebAPI没有';t在控制器上维护窗体身份验证,c#,asp.net,api,controller,C#,Asp.net,Api,Controller,情况就是这样: 我拥有一个AccountController,它继承自ApiController,看起来像这样 [HttpPost] [ActionName("Login")] public HttpResponseMessage Login() { string emailOrUsername = base.Request.GetQueryNameValuePairs().ElementAt(0).Value; FormsAuth

情况就是这样:

我拥有一个AccountController,它继承自ApiController,看起来像这样

    [HttpPost]
    [ActionName("Login")]
    public HttpResponseMessage Login()
    {
        string emailOrUsername = base.Request.GetQueryNameValuePairs().ElementAt(0).Value;
        FormsAuthentication.SetAuthCookie(emailOrUsername, false);
        return Request.CreateResponse<string>(HttpStatusCode.OK, emailOrUsername);
    }
    [HttpGet]
    [Authorize]
    [ActionName("Logout")]
    public HttpResponseMessage Logout()
    {
        FormsAuthentication.SignOut();
        return Request.CreateResponse<string>(HttpStatusCode.OK, "Hope to see you again!");
    }
[HttpPost]
[ActionName(“登录”)]
公共HttpResponseMessage登录()
{
字符串emailOrUsername=base.Request.GetQueryNameValuePairs().ElementAt(0).Value;
FormsAuthentication.SetAuthCookie(emailOrUsername,false);
return Request.CreateResponse(HttpStatusCode.OK,emailOrUsername);
}
[HttpGet]
[授权]
[操作名称(“注销”)]
公共HttpResponseMessage注销()
{
FormsAuthentication.SignOut();
returnrequest.CreateResponse(HttpStatusCode.OK,“希望再次见到您!”);
}
我还拥有一个MessageController,它也继承自ApiController,如下所示:

    [HttpPost]
    [Authorize]
    [ActionName("ReceiveMessage")]
    public HttpResponseMessage ReceiveMessage()
    {
        return Request.CreateResponse<string>(HttpStatusCode.OK, "Successfully received your message");
    }
[HttpPost]
[授权]
[ActionName(“ReceiveMessage”)]
公共HttpResponseMessage ReceiveMessage()
{
return Request.CreateResponse(HttpStatusCode.OK,“成功接收到您的消息”);
}
所以,AccountController工作完美,我可以登录并注销。 这就是棘手和令人困惑的部分开始的地方。当我在同一台计算机(本地主机)上进行测试时,我能够在获得授权后访问ReceiveMessage。 到目前为止还不错

我现在编辑了文档\IISExpress\config\applicationhost.config并编辑了绑定: 绑定协议=“http”bindingInformation=“:60967:”

因此,我可以从另一台设备访问我的WebApi。我可以登录和注销,但我无法从这个新设备访问ReceiveMessage(登录完成后)——而在本地主机上,我可以做任何我想做的事情


我做错了什么?(这是一个示例,我计划让多个用户连接到api,因此在某个地方使用静态变量不是一个选项)

浏览器方面的工作很好,@charlie Brown是正确的,问题与cookie有关--我是从unity应用程序访问它的

哪个设备?那个设备支持cookies吗?