Skip to main content
 首页 » 编程设计

c#之如何从 HttpresponseMessage Asp.net Web Api 返回不记名 token

2024年02月04日32www_RR

我怎样才能从 web api 返回 token ,以便我可以在 javascript 中设置该 token 的 cookie? 这样我就生成了 token

   [Route("api/agency/login")] 
    [HttpPost] 
    public HttpResponseMessage loginApi([FromBody] Users UserObj) 
    { 
           var tokanObj = method.AccessToken(UserObj.username, UserObj.Password, "password"); 
 
   //How to return this token ?? 
    } 

请您参考如下方法:

你试过了吗StringContent ?

return new HttpResponseMessage( HttpStatusCode.OK )  
{ 
    Content =  new StringContent( "Your token here" )  
};