protected void Page_Load(object sender, EventArgs e) { string mode = Request.Params["openid.mode"]; if (!String.IsNullOrEmpty(mode)) { if (!expecting_redir) return; expecting_redir = false; HttpSessionStateBase sessionBase = new HttpSessionStateWrapper(Session); RP.CurrentSession = sessionBase; YahooAuthenticationResponse resp = RP.ParseAuthenticationResponse(Request); if (resp == null) return; notLoggedIn.Visible = false; LoggedIn.Visible = true; if (RP.SignInRP(resp) != null) logged_id.InnerHtml = String.Format("Your ID is {0}", Request.Params["openid.identity"]); else logged_id.InnerHtml = String.Format("Verification Failed"); } else { notLoggedIn.Visible = true; LoggedIn.Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { HttpSessionStateBase sessionBase = new HttpSessionStateWrapper(Session); RP.CurrentSession = sessionBase; LiveIDAuthenticationResponse codeResp = (LiveIDAuthenticationResponse)RP.parseAuthenticationResponse(HttpContext.Current.Request); if (codeResp == null) return; RP.SignInRP(codeResp); }
public HttpResponseMessage Get() { Dictionary<string, object> response = new Dictionary<string, object>(); System.Web.SessionState.HttpSessionState state = System.Web.HttpContext.Current.Session; HttpSessionStateBase session = new HttpSessionStateWrapper(state); //HttpSessionStateBase session = new HttpSessionStateWrapper(HttpContext.Current.Session); //Debug.WriteLine("Getting Session: " + SessionExtensions.GetDataFromSession<string>(session, "CurrentSession")); //Debug.WriteLine("Getting Session 2:" + this.Session["CurrentSession"].ToString()); response.Add("SessionId", SessionExtensions.GetDataFromSession<string>(session, "CurrentSession")); return Request.CreateResponse<Dictionary<string, object>> (HttpStatusCode.OK,response); }
public void OnException(ExceptionContext filterContext) { HttpContext ctx = HttpContext.Current; Exception ex = ctx.Server.GetLastError(); ctx.Response.Clear(); RequestContext rc = ((MvcHandler)ctx.CurrentHandler).RequestContext; IController controller = new HomeController(); // Здесь можно использовать любой контроллер var context = new ControllerContext(rc, (ControllerBase)controller); var viewResult = new ViewResult(); var httpException = ex as HttpException; if (httpException != null) { switch (httpException.GetHttpCode()) { //страницы будут искаться в Views/Shared case 404: viewResult.ViewName = "Error404"; break; case 500: viewResult.ViewName = "Error500"; break; default: viewResult.ViewName = "Error"; break; } } else { viewResult.ViewName = "Error"; } viewResult.ViewBag.Message = filterContext.Exception.Message; //logging HttpSessionStateBase sessionBase = new HttpSessionStateWrapper(ctx.Session); AppLogger.Error(sessionBase, filterContext.Exception.Message); try{ viewResult.ViewBag.TargetSite = filterContext.Exception.TargetSite; viewResult.ViewBag.StackTrace = filterContext.Exception.StackTrace; }catch(Exception e){} viewResult.ExecuteResult(context); ctx.Server.ClearError(); }
public override bool ValidateUser(string username, string password) { var user = (from u in db.users where u.USERNAME == username && u.USERPASS.Trim() == password.Trim() select u).FirstOrDefault(); bool valid = user == null ? false : true; if (valid) { var s = new HttpSessionStateWrapper(HttpContext.Current.Session); s.Add("UserSessionObject", user); } return valid; }
public HttpResponseMessage UpVote(int? id) { if (ModelState.IsValid) { var dealId = (int)id; var session = new HttpSessionStateWrapper(HttpContext.Current.Session); var userId = ((user)session["UserSessionObject"]).USER_ID; var db = new Entities(); var vote = db.deals_votes.Where(d => d.DEALS_ID == dealId && d.USERS_ID == userId); if (vote != null) return Request.CreateResponse(HttpStatusCode.OK); var nvote = new deals_votes(); nvote.DEALS_ID = dealId; nvote.USERS_ID = userId; nvote.VOTE = 1; db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, nvote); response.Headers.Location = new Uri(Url.Link("DefaultApi", null)); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }