Posted Thu, 23 Jul 2015 19:34:29 GMT in reply to
Lemonfiend
Reply
On Thu, 23 Jul 2015 18:33:21 GMT, Lemonfiend wrote:
class SomeWebInterface
{
void get()
{
...
runTask(toDelegate(&someTask));
...
}
private auto someTask()
{
...
mySessionVar = "hello";
...
}
}
Is there any way to have someTask set a SessionVar?
You can find an answer to this by reading the web interface generator in the docs:
http://vibed.org/docs#web-interface-generator
Basically, you would need to do this:
class SomeWebInterface
{
private SessionVar!(string, "mySessionVar") ms_mySessionVar;
void getIndex()
{
...
someTask(); // The request info is task local. So, if you run this as a delegate in another task, the details about the request will be lost and you will get a segmentation fault! All requests have their own task, so it should not be necessary.
...
}
private auto someTask()
{
ms_mySessionVar = "hello"; // This will automatically emit a unique session cookie in the user's browser and set his server-side variable in the session storage of your choosing (in the HTTPServerSettings.sessionStore), so that it is available regardless of connection state.
}
}
You can access this page using GET http://domain:port/index