- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在开发一个原型(prototype)程序,它应该测试 ASP.NET 的不同(SessionState、Profile 等)提供程序,即 MySQL、Oracle 等。目前我正在使用 MySQL 提供程序。我刚刚设法实例化了提供者、SessionStateContainer 和 SessionState 本身。
Type mySqlType = Type.GetType("MySql.Web.SessionState.MySqlSessionStateStore, MySql.Web, Version=6.6.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d", true, true);
SessionStateStoreProviderBase provider = (SessionStateStoreProviderBase)Activator.CreateInstance(mySqlType);
System.Collections.Specialized.NameValueCollection providerConfig = new System.Collections.Specialized.NameValueCollection();
providerConfig.Add("connectionStringName", "LocalMySqlServer");
providerConfig.Add("applicationName", "/");
providerConfig.Add("autogenerateschema", "True");
providerConfig.Add("enableExpireCallback", "False");
provider.Initialize("MySqlSessionStateProvider", providerConfig);
HttpContext context = new HttpContext(
new HttpRequest("fake", "http://localhost:14359", ""),
new HttpResponse(new StringWriter()));
SessionStateStoreData storeData = provider.CreateNewStoreData(context, 100);
System.Web.SessionState.HttpSessionStateContainer sessionStateContainer =
new System.Web.SessionState.HttpSessionStateContainer(
"mySession",
storeData.Items,
storeData.StaticObjects,
100,
true,
System.Web.HttpCookieMode.UseDeviceProfile,
SessionStateMode.Custom,
false
);
Type sessionStateType = Type.GetType("System.Web.SessionState.HttpSessionState, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
HttpSessionState sessionState =
(HttpSessionState)sessionStateType
.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(IHttpSessionState) }, null)
.Invoke(new object[] { ssessionStateContainer });
provider.InitializeRequest(context);
一切似乎都运行良好,因为我可以在创建的 session 中写入一些值,并且可以从那里读取它们:
sessionStateContainer.Add("SomeKey", "SomeValue");
var test = sessionStateContainer["SomeKey"];
Console.WriteLine("var test: " + test.ToString()); // outputs "var test: SomeValue"
sessionState.Add("AnotherKey", "SomeOtherValue");
var test2 = sessionState["AnotherKey"];
Console.WriteLine("var test2: " + test2.ToString()); // outputs "var test2: SomeOtherValue"
// End the request
provider.EndRequest(context);
有趣的部分来了 - 当我检查数据库中的 my_aspnet_sessions
表时,里面什么也没有。
所以我想知道数据写在哪里了还是我做错了什么?
更新:
尽管这个问题不再是障碍,但我仍然很想知道,如果有人愿意尝试一下,这是我使用过的 connectionString
:
<connectionStrings>
<remove name="LocalMySqlServer" />
<add name="LocalMySqlServer" connectionString="server=localhost;database=session_test;User Id=user;password=pass" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
您还需要 MySQL Connector NET .
最佳答案
您在数据库中看不到任何数据,因为 SessionStateModule等待请求端调用命令SetAndReleaseItemExclusive .在调用此类命令之前,数据一直保存在内存中。事实上,文档指出:
The SessionStateModule object calls the SetAndReleaseItemExclusive method at the end of a request, during the ReleaseRequestState event, to insert current session-item information into the data store or update existing session-item information in the data store with current values, to update the expiration time on the item, and to release the lock on the data. Only session data for the current application that matches the supplied session id and lockId values is updated. For more information about locking, see "Locking Session Store Data" in the SessionStateStoreProviderBase class overview.
要深入了解详细信息,您可以查看 relevant files from the mono codebase .
鉴于此,要在数据库中查看您的 session 数据,您应该执行如下操作:
object storeLockId = new object();
sessionStateContainer.Add("SomeKey", "SomeValue");
var test = sessionStateContainer["SomeKey"];
Console.WriteLine("var test: " + test.ToString());
sessionState.Add("AnotherKey", "SomeOtherValue");
var test2 = sessionState["AnotherKey"];
Console.WriteLine("var test2: " + test2.ToString());
// End the request
provider.SetAndReleaseItemExclusive (context, sessionStateContainer.SessionID,
storeData, storeLockId, true);
provider.EndRequest(context);
关于c# - 手动实例化的 SessionState 提供程序的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15820806/
我已将 session 状态超时设置为 60,即 1 小时。但是,用户在 20 分钟后仍然收到 session 过期消息。 我们使用 Windows Server 2008 来托管 asp.net 应
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Can I access session state from an HTTPModule? 我已经设置并正
我已将sessionState配置为使用下面的自定义SQL服务器,并将其设置为1分钟后过期。 session 似乎始终保留在浏览器和sql服务器上。我什至将regenerateExpiredSessi
可以这样说 “如果您遇到这些情况,则必须使用 SessionState 来在回发之间存储您的值。” 您能否列出迫使 asp.net 开发人员从 ViewState、HiddenFields 或查询字符
当 Session 过期时,是否可以控制 ASP.NET 的行为?似乎默认行为是将用户发送到网站根目录。期望的效果是将用户发送到自定义的“ session 已过期”页面。 澄清一下,SessionSt
我的计算机上有一个遗留的 ASP.NET soap Web 服务。该服务具有此注释: [WebMethod(EnableSession = true)] 关于几种方法并使用Session属性保存一些
我正在开发一个原型(prototype)程序,它应该测试 ASP.NET 的不同(SessionState、Profile 等)提供程序,即 MySQL、Oracle 等。目前我正在使用 MySQL
我们正在使用进程外 session 状态服务/ASP.Net session 状态。我们知道这有问题,因为它在过去被滥用,在 session 状态中经常存储太多内容,所以我们正在转向更具可扩展性的系统
文件 c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config 没有这个元素。这些选项保留在哪里? 最佳答案 的默认设置
当我导入 SessionState 时,我正在尝试使用 streamlit SessionState。我收到以下错误:ModuleNotFoundError: No module named 'Ses
我编写了一个 .NET 应用程序,希望使用(至少)两个虚拟机、一个负载均衡器和一个 SQL 服务器数据库将其托管在 Azure 上。 根据this页面上,我必须在表存储、SQL Server 和 Re
我正在查看有关网站 session 超时的代码。在 web.config 中我遇到了这段代码。 有谁知道其中一个是否优先于另一个,以及它们有何不同。谢谢。 最佳答案 它们是不同的东西。
我有一个网站,我使用 ASP.NET 成员资格来管理用户创建、登录、角色管理。我使用 Visual Studio 2012。web.config 中有很多由 Visual Studio 创建的元素。与
我正在努力扩展我们的网络应用程序以在网络场上工作。我已经编写了一个自定义 session 状态提供程序。所有部分似乎都可以自己工作,但网站最终会停止响应,直到我清除 session cookie,然后
我将 ViewState["zzz"] 和 Session["zzz"] 设置为相同的字符串。 当我使用 == 进行比较时,我得到错误。 当我执行 ViewState["zzz"].Equals(Se
我们想在 SQL Server 中存储 session 。我们有 sessionState mode="SQLServer"。我得到了一个示例连接字符串,如下所列。在此它同时具有 stateConne
示例应用程序包括一个 Suspension Manager 类,该类将 session 状态存储在 Dictionary 中,但绝不会尝试在其中存储除字符串之外的任何内容。 每当我存储除字符串之外的任
在我的 Windows 应用商店应用程序中,我将数据直接存储在 sessionState 对象中,因此我以后不需要将数据移动到那里。在一种情况下,我存储一个对象,该对象具有用于在包含范围内声明的变量的
我试图减少一个站点的 session 。所以添加 到我的 web.config。之后,如果我执行 Session["test"] = "yes"; 我收到错误消息“对象引用未设置为对象的实例。”这可
我在 MVC 应用程序中使用 Redis 缓存 session 状态提供程序。当然,提供程序的所有设置都在我的 Web.config 中。如果我简单地将主机和 key 以及所有这些内容放入简单的字符串
我是一名优秀的程序员,十分优秀!