Use Session ID from supplied parameter instead of default behavior in ASP.NET MVC3

六月ゝ 毕业季﹏ 提交于 2020-01-02 23:09:31

问题


I am writing a simple proof-of-concept web service using ASP.NET MVC3 controller with JSON input/output. I want to allow a login based on a DB table and to return an API key and a session ID. With subsequent requests to other APIs I require passing both API key and a session ID.

How can I set up my MVC3 project so that neither cookie nor cookieless session is being used. I want the session ID from JSON request to be used instead and still have the convenience of a Controller.Session. Is this possible? I don't want to reinvent the wheel with my own session handling.


回答1:


YOu can use the ISessionIDManager interface to create custom logic for storing and retrieving the sessionID.

You set in your web.config that the app uses your custom session id manager instead of the default one and then all you have to do is figure out how you want it to save to the request and retrieve from the request.



来源:https://stackoverflow.com/questions/6331984/use-session-id-from-supplied-parameter-instead-of-default-behavior-in-asp-net-mv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!