/// <summary> /// 获取验证码数值 /// </summary> /// <returns></returns> public static string GetVerifyCode() { string vcode = ""; if (HttpContext.Current != null && HttpContext.Current.Session != null) { vcode = SessionState.Get(Fetch.UC_VERIFY_CODE_KEY) as string; //Session 保存,无需解密 if (!string.IsNullOrEmpty(vcode)) { return(vcode); } } else { vcode = Utility.GetCookie(Fetch.UC_VERIFY_CODE_KEY); } if (!String.IsNullOrEmpty(vcode)) { vcode = CWHEncryptNet.XorCrevasse(vcode); } return(vcode); }
/// <summary> /// 绑定数据 /// </summary> protected void BindRankData( ) { string tag = "MatchRank"; object ob = SessionState.Get(tag); if (SessionState.Get("MatchRank") == null) { TreasureFacade treasureFacade = new TreasureFacade(kindID); string sqlQuery = "Select Top 100 * from GameScoreInfo(nolock) order by Score desc"; DataSet ds = treasureFacade.GetDataSetByWhere(sqlQuery); if (ds.Tables[0].Rows.Count > 0) { rptRank.DataSource = ds; rptRank.DataBind( ); } SessionState.Set(tag, ob, 10); } else { DataSet ds = ( DataSet )ob; if (ds.Tables[0].Rows.Count > 0) { rptRank.DataSource = ds; rptRank.DataBind( ); } } }
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { if (SessionState.Get(SessionKeys.AdminSession) == null) { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { area = "CPanel", controller = "CPAuthentication", action = "Login" })); } }
public ActionResult PartnerRequestList() { SessionState sessionState = new SessionState(); int partnerId = (int)sessionState.Get(SessionKeys.PartnerSession); PartnerViewModel = new PartnerViewModel(); PartnerViewModel.PartnerRequestList = partnerLogic.PartnerRquestListByPartner(partnerId); return(View(PartnerViewModel)); }
public ActionResult Login(AdminModel adminLogin) { if (SessionState.Get(SessionKeys.AdminSession) == null) { return(View()); } else { return(RedirectToAction("Home", "CPParking")); } }
public ActionResult PartnerCopP() { SessionState sessionState = new SessionState(); int partnerId = (int)sessionState.Get(SessionKeys.PartnerSession); var requestResult = partnerLogic.GetPartner(partnerId); PartnerViewModel = new Models.PartnerViewModel() { PartnerModel = requestResult }; return(View("PartnerCop", PartnerViewModel)); }
public ActionResult PartnerRequest(Model.PartnerRequest partnerRequest) { SessionState sessionState = new SessionState(); partnerRequest.PartnerRefId = (int)sessionState.Get(SessionKeys.PartnerSession); var requestResult = partnerLogic.AddPartnerRequest(partnerRequest); PartnerViewModel = new Models.PartnerViewModel(); PartnerViewModel.PartnerRequest = new Model.PartnerRequest() { EndUserMessage = requestResult.EndUserMessage }; return(View(PartnerViewModel)); }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state) { var key = parameter as string; if (key != null && SessionState.ContainsKey(key)) { ShareOperation = SessionState.Get <ShareOperation>(key); } else { Content = "Opened without using share"; return; } try { if (this.ShareOperation.Data.Contains(StandardDataFormats.Html)) { Content = (await ShareOperation.Data.GetHtmlFormatAsync()).ToString(); } else if (ShareOperation.Data.Contains(StandardDataFormats.Text)) { Content = (await ShareOperation.Data.GetTextAsync()).ToString(); } else if (ShareOperation.Data.Contains(StandardDataFormats.WebLink)) { Content = (await ShareOperation.Data.GetWebLinkAsync()).AbsoluteUri; } else if (ShareOperation.Data.Contains(StandardDataFormats.ApplicationLink)) { Content = (await ShareOperation.Data.GetApplicationLinkAsync()).AbsoluteUri; } else if (ShareOperation.Data.Contains(StandardDataFormats.Bitmap)) { Content = nameof(StandardDataFormats.Bitmap); var bitmap = await ShareOperation.Data.GetBitmapAsync(); using (var stream = await bitmap.OpenReadAsync()) { Bitmap = new BitmapImage(); Bitmap.SetSource(stream); } } else if (ShareOperation.Data.Contains(StandardDataFormats.StorageItems)) { Content = nameof(StandardDataFormats.StorageItems); foreach (var item in await ShareOperation.Data.GetStorageItemsAsync()) { Content += item.Path + Environment.NewLine; } } else { Content = "Some unsupported share type."; return; } QuickLink = ShareOperation.QuickLinkId ?? "None set"; if (ShareOperation.Data.Properties.Square30x30Logo != null) { using (var stream = await ShareOperation.Data.Properties.Square30x30Logo.OpenReadAsync()) { Logo = new BitmapImage(); Logo.SetSource(stream); } } if (ShareOperation.Data.Properties.Thumbnail != null) { using (var stream = await ShareOperation.Data.Properties.Thumbnail.OpenReadAsync()) { Thumbnail = new BitmapImage(); Thumbnail.SetSource(stream); } } } catch (Exception e) { Content = e.Message; } }
public void ThreadSafeSetAndGet() { //Set up store if (System.IO.Directory.Exists("store")) { System.IO.Directory.Delete("store", true); } SessionID sessionId = new SessionID("FIX.4.2", "SENDERCOMP", "TARGETCOMP"); Dictionary config = new Dictionary(); config.SetString(SessionSettings.CONNECTION_TYPE, "initiator"); config.SetString(SessionSettings.FILE_STORE_PATH, "store"); SessionSettings settings = new SessionSettings(); settings.Set(sessionId, config); FileStoreFactory factory = new FileStoreFactory(settings); FileStore store = (FileStore)factory.Create(sessionId); NullLog log = new NullLog(); //Set up sessionstate SessionState state = new SessionState(log, 1) { MessageStore = store }; Hashtable errorsTable = Hashtable.Synchronized(new Hashtable()); //used in more than 1 thread at a time Hashtable setTable = new Hashtable(1000); //only used in 1 thread at a time Hashtable getTable = new Hashtable(1000); //only used in 1 thread at a time //Synchronously populate 1000 messages for (int i = 1; i < 1000; i++) { string msg = "msg" + i; state.Set(i, msg); setTable[i] = msg; } //Simulate background sending of messages that populate into the store AutoResetEvent setEvent = new AutoResetEvent(false); ThreadPool.QueueUserWorkItem(delegate(object stateObject) { AutoResetEvent internalSetEvent = (AutoResetEvent)((object[])stateObject)[0]; SessionState internalState = (SessionState)((object[])stateObject)[1]; for (int i = 1001; i < 2000; i++) { try { internalState.Set(i, "msg" + i); } catch (System.IO.IOException ex) { errorsTable[ex.Message] = ex; } } internalSetEvent.Set(); } , new object[] { setEvent, state }); //Simulate background reading of messages from the store - like is done in a resend request answer AutoResetEvent getEvent = new AutoResetEvent(false); ThreadPool.QueueUserWorkItem(delegate(object stateObject){ AutoResetEvent internalGetEvent = (AutoResetEvent)((object[])stateObject)[0]; SessionState internalState = (SessionState)((object[])stateObject)[1]; for (int i = 1; i < 1000; i++) { try { List <string> lst = new List <string>(1); internalState.Get(i, i, lst); if (lst.Count == 0) { getTable[i] = "nothing read"; } else { getTable[i] = lst[0]; } } catch (System.IO.IOException ex) { errorsTable[ex.Message] = ex; } } internalGetEvent.Set(); } , new object[] { getEvent, state }); //wait till done and assert results Assert.True(setEvent.WaitOne(10000), "Get or Set hung/timed out during concurrent usage"); Assert.True(getEvent.WaitOne(10000), "Get or Set hung/timed out during concurrent usage"); Assert.AreEqual(setTable, getTable, "Garbled data read in concurrent set and get (like between resendrequest and send)"); Assert.AreEqual(errorsTable.Count, 0, "IOException occured in concurrent set and get (like between resendrequest and send)"); //Tear down filestore state.Dispose(); store.Dispose(); }
/// <summary> /// 获取老的密保回答 /// </summary> /// <returns></returns> public static AccountsProtect GetOldProtectionInfo(int userID) { string sessionKey = string.Format("old_{0}", Fetch.GetSessionProtectionKey(userID)); return(SessionState.Get(sessionKey) as AccountsProtect); }
public BaseController() { try { // // process authentication if a provider is configured // // string authNProviderName = ConfigurationManager.AppSettings["AuthenticationProvider"]; if (!string.IsNullOrEmpty(authNProviderName)) { Type authNProviderType = Type.GetType(authNProviderName); if (authNProviderType == null) { SendError(401, "Unable to load authentication provider."); } // only send 408 error when the request is ajax and authenticated user is unknown if (System.Web.HttpContext.Current.Request.Headers["X-Requested-With"] == "XMLHttpRequest" && SessionState.Get(System.Web.HttpContext.Current.Session.SessionID, AUTH_USER) == null) { SendError(408, "Session timed out."); return; } IAuthentication authNProvider = (IAuthentication)Activator.CreateInstance(authNProviderType); _authenticatedUser = authNProvider.Authenticate(System.Web.HttpContext.Current.Session); SessionState.Set(System.Web.HttpContext.Current.Session.SessionID, AUTH_USER, _authenticatedUser); if (System.Web.HttpContext.Current.Response.IsRequestBeingRedirected) { return; } if (string.IsNullOrEmpty(_authenticatedUser)) { SendError(401, "Authentication failed."); } // // process authorization if a provider is configured // string authZProviderName = ConfigurationManager.AppSettings["AuthorizationProvider"]; if (!string.IsNullOrEmpty(authZProviderName)) { Type authZProviderType = Type.GetType(authZProviderName); if (authZProviderType == null) { SendError(401, "Unable to load authorization provider."); } IAuthorization authZProvider = (IAuthorization)Activator.CreateInstance(authZProviderType); bool authorized = authZProvider.Authorize(System.Web.HttpContext.Current.Session, "adapterAdmins", _authenticatedUser); if (!authorized) { SendError(401, "User [" + _authenticatedUser + "] not authorized."); } } // // get authorization headers if a provider is configured // try { string headersProviderName = ConfigurationManager.AppSettings["AuthHeadersProvider"]; if (!string.IsNullOrEmpty(headersProviderName)) { Type headersProviderType = Type.GetType(headersProviderName); if (headersProviderType == null) { SendError(401, "Unable to load auth header provider."); } IAuthHeaders headersProvider = (IAuthHeaders)Activator.CreateInstance(headersProviderType); _authHeaders = headersProvider.Get(_authenticatedUser); } } catch (Exception e) { _logger.Error("Error getting authorization headers: " + e); throw e; } } } catch (Exception e) { _logger.Error("Authentication error: " + e.Message + ": " + e.StackTrace.ToString()); SendError(401, e.ToString()); } }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state) { var key = parameter as StateItemKey; if (key != null && SessionState.Contains(key)) { ShareOperation = SessionState.Get <ShareOperation>(key); } else { Content = "Opened without using share"; return; } try { if (this.ShareOperation.Data.Contains(StandardDataFormats.Html)) { Content = (await ShareOperation.Data.GetHtmlFormatAsync()).ToString(); } else if (ShareOperation.Data.Contains(StandardDataFormats.Text)) { Content = (await ShareOperation.Data.GetTextAsync()).ToString(); } else if (ShareOperation.Data.Contains(StandardDataFormats.WebLink)) { Content = (await ShareOperation.Data.GetWebLinkAsync()).AbsoluteUri; } else if (ShareOperation.Data.Contains(StandardDataFormats.ApplicationLink)) { Content = (await ShareOperation.Data.GetApplicationLinkAsync()).AbsoluteUri; } else if (ShareOperation.Data.Contains(StandardDataFormats.Bitmap)) { Content = nameof(StandardDataFormats.Bitmap); var bitmap = await ShareOperation.Data.GetBitmapAsync(); using (var stream = await bitmap.OpenReadAsync()) { Bitmap = new BitmapImage(); Bitmap.SetSource(stream); } } else if (ShareOperation.Data.Contains(StandardDataFormats.StorageItems)) { Content = nameof(StandardDataFormats.StorageItems); foreach (var item in await ShareOperation.Data.GetStorageItemsAsync()) { Content += item.Path + Environment.NewLine; } } else { Content = "Some unsupported share type."; return; } QuickLink = ShareOperation.QuickLinkId ?? "None set"; if (ShareOperation.Data.Properties.Square30x30Logo != null) { using (var stream = await ShareOperation.Data.Properties.Square30x30Logo.OpenReadAsync()) { Logo = new BitmapImage(); Logo.SetSource(stream); } } if (ShareOperation.Data.Properties.Thumbnail != null) { using (var stream = await ShareOperation.Data.Properties.Thumbnail.OpenReadAsync()) { Thumbnail = new BitmapImage(); Thumbnail.SetSource(stream); } } } catch (Exception e) { Content = e.Message; } finally { var folder = await Package.Current.InstalledLocation.GetFolderAsync("Assets"); var file = await folder.GetFileAsync("T10 56x56.png"); var reference = RandomAccessStreamReference.CreateFromFile(file); var quick = new QuickLink() { Id = "Template10 QuickLink", Title = "Template10 QuickLink", Thumbnail = reference, }; quick.SupportedFileTypes.Clear(); quick.SupportedFileTypes.Add(StandardDataFormats.Text); quick.SupportedFileTypes.Add(StandardDataFormats.WebLink); quick.SupportedFileTypes.Add(StandardDataFormats.ApplicationLink); quick.SupportedFileTypes.Add(StandardDataFormats.Bitmap); quick.SupportedFileTypes.Add(StandardDataFormats.Html); ShareOperation.ReportCompleted(quick); } }