- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经为此苦苦挣扎了一段时间。
我使用以下代码实现了一个基本的 IHttpHandler,SESSION 不断更新:
namespace ClassLibrary1
{
public class MyHandler : IHttpHandler, IRequiresSessionState
{
public bool IsReusable
{
get
{
return true;
}
}
public void ProcessRequest(HttpContext context)
{
context.Response.Write(context.Session.SessionID + "</br>");
context.Response.Write(DateTime.Now.TimeOfDay.ToString() + "</br>");
}
}
}
如您所见,非常简单的代码。然后我简单地创建一个文件夹 c:\Inetpub\wwwroot\Test。然后我添加一个 bin 文件夹并将我的 dll 放入 bin 文件夹中。
我的 web.config 文件看起来像这样:
<configuration>
<system.webServer>
<handlers>
<add verb="*.x" path="*" name="MyHandler" type="ClassLibrary1.MyHandler" />
</handlers>
</system.webServer>
</configuration>
然后我打开 IIS (IIS 7.0),我必须右键单击默认网站下的测试文件夹,然后单击转换为应用程序。这使它成为一个站点。
然后我转到浏览器并转到 http://localhost/Test/
然后我得到这样的东西: fxnjswtkkzs1silahvpf5xun 09:48:52.9194609
如果我按 F5 或刷新页面, session ID 会更改。这是不应该发生的。
我就是想不通。有趣的是它昨天确实有效。有人可以帮忙....
ps,firefox 和 ie 中的行为相同
提前致谢
最佳答案
是的,您应该每次都获得一个新的SessionID
,不仅在您的GenericHandler 上,而且在一个简单的ASPX 页面上除非您访问您的Session
对象。试试这个:
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
object o = context.Session["counter"];
if (o == null)
context.Session["counter"] = 1;
else
context.Session["counter"] = ((int) o) + 1;
context.Response.Write(context.Session.SessionID + "\r\n");
context.Response.Write(context.Session["counter"]);
}
关于c# - IRequiresSessionState 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8110354/
我已经为此苦苦挣扎了一段时间。 我使用以下代码实现了一个基本的 IHttpHandler,SESSION 不断更新: namespace ClassLibrary1 { public clas
我需要能够在看到 session 状态时进行更改。我发现了 IRequiresSessionState 标记接口(interface),但一直无法弄清楚如何使用它。我想我可能遗漏了一些明显的东西。你们
IRequiresSessionState 和 IReadOnlySessionState 除了无法保存对 session 变量的更改外,还有什么区别? 两者都使我能够在我的 HttpHandler
我有实现 IRequiresSessionState 的 ASHX HTTPHandler。当我调用此处理程序并在另一个窗口中调用同一应用程序的 aspx 页面时,aspx 页面在 ashx 页面完成
我的应用程序有时会在 global.asax 的 Application_OnPostAuthenticateRequest 事件中调用 Server.Transfer 来充当某种 url 重写。当发
我是一名优秀的程序员,十分优秀!