Authenticating ASP.NET Web API

前端 未结 2 435
天命终不由人
天命终不由人 2021-01-31 19:40

I\'ve created a new ASP.NET Web API and things are working well. I\'m at the point now where I want to secure the API.

I put the [Authorize] attribute above my base con

2条回答
  •  深忆病人
    2021-01-31 20:12

    Basically you'll want to send the username and password encrypted over the net to your server application, then you can let your API generate a random session ID and keep it in a list (serverside) and send the ID back to the client. Now each time your client sends something to the server, include the ID he received in the packets and so the server can check it each time.

    On client disconnection or fixed timeout you can remove the ID from the server list and ask the client to re-authenticate.

提交回复
热议问题