Universe.Framework.Servers.HttpServer.Implementation.OSHttpResponse.AddCookie C# (CSharp) Method

AddCookie() public method

public AddCookie ( System cookie ) : void
cookie System
return void
        public void AddCookie(System.Web.HttpCookie cookie)
        {
            try {
                _httpResponse.Cookies.Add (new Cookie (cookie.Name, cookie.Value, cookie.Path, cookie.Domain) {
                    Expires = cookie.Expires
                });
            } catch {
            }
        }

Usage Example

        public Dictionary<string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
            OSHttpResponse httpResponse, Dictionary<string, object> requestParameters,
            ITranslator translator, out string response)
        {
            response = null;
            var vars = new Dictionary<string, object>();

            string error = "";
            if (requestParameters.ContainsKey("username") && requestParameters.ContainsKey("password"))
            {
                string username = requestParameters["username"].ToString();
                string password = requestParameters["password"].ToString();

                ILoginService loginService = webInterface.Registry.RequestModuleInterface<ILoginService>();
                if (loginService.VerifyClient(UUID.Zero, username, "UserAccount", password))
                {
                    UUID sessionID = UUID.Random();
                    UserAccount account =
                        webInterface.Registry.RequestModuleInterface<IUserAccountService>()
                                    .GetUserAccount(null, username);
                    Authenticator.AddAuthentication(sessionID, account);
                    if (account.UserLevel > 0)
                        Authenticator.AddAdminAuthentication(sessionID, account);
                    httpResponse.AddCookie(new System.Web.HttpCookie("SessionID", sessionID.ToString())
                                               {
                                                   Expires = DateTime.MinValue,
                                                   Path = ""
                                               });

                    response = "<h3>Successfully logged in, redirecting to main page</h3>" +
                               "<script language=\"javascript\">" +
                               "setTimeout(function() {window.location.href = \"index.html\";}, 0);" +
                               "</script>";
                }
                else
                    response = "<h3>Failed to verify user name and password</h3>";
                return null;
            }

            vars.Add("ErrorMessage", error);
            vars.Add("Login", translator.GetTranslatedString("Login"));
            vars.Add("UserNameText", translator.GetTranslatedString("UserName"));
            vars.Add("PasswordText", translator.GetTranslatedString("Password"));
            vars.Add("ForgotPassword", translator.GetTranslatedString("ForgotPassword"));
            vars.Add("Submit", translator.GetTranslatedString("Login"));

            return vars;
        }
All Usage Examples Of Universe.Framework.Servers.HttpServer.Implementation.OSHttpResponse::AddCookie