ContextFactoryCreateBySessionKey Method |
Creates a new context of execution for the user behind the session key.
Namespace: AskiaPortalCmn
The context created will restrict the usage of API methods according to the role of the user.
If the session key is invalid,
it return an invalid context.
You may check the validity of
the context using Validate.
This example shows a typical usage of session key and context.
public void SignIn() { string apiKey = Request.Params["apiKey"]; string login = Request.Params["login"]; string password = Request.Params["password"]; var context = ContextFactory.CreateByLoginAndPassword(login, password, apiKey); var validation = context.Validate(); if (!validation.Success) { throw validation.Exception; } var sessionKey = context.BuildSessionKey(); if (!sessionKey.Success) { throw successKey.Exception; } var cookie = new HttpCookie("session", sessionKey.Value); Response.Cookies.Add(cookie); } public void DoAuthenticatedAction() { var apiKey = Request.Params["apiKey"]; var sessionKey = Request.Cookies["session"].Value; var context = ContextFactory.CreateBySessionKey(sessionKey, apiKey); var validation = context.Validate(); if (!validation.Success) { throw validation.Exception; } IUser currentUser = context.User; // Rest of the code... }