IRequiresSessionState 不起作用

发布于 12-15 08:28 字数 1343 浏览 2 评论 0原文

我已经为此苦苦挣扎了一段时间了。

我使用以下代码实现了一个基本的 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),必须右键单击默认网站下的 Test 文件夹,然后单击“转换为应用程序”。这使它成为一个网站。

然后我转到浏览器,然后转到 http://localhost/Test/

然后我得到如下内容: fxnjswtkkzs1silahvpf5xun 09:48:52.9194609

如果我按 F5 或刷新页面,会话 ID 会更改。 这是不应该发生的。

我就是无法弄清楚这一点。有趣的是,它昨天确实起作用了。 有人可以帮忙吗....

ps,firefox 和 ie 中的行为相同,

提前致谢

I have been struggling with this a while now.

I implemented a basic IHttpHandler with the following code and SESSION keeps being newed up:

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>");
        }
    }
}

As you can see, very simple code.
Then I simply create a folder c:\Inetpub\wwwroot\Test.
I then add a bin folder and put my dll into the bin folder.

My web.config file then looks like this:

<configuration>
<system.webServer>
      <handlers>
        <add verb="*.x" path="*" name="MyHandler" type="ClassLibrary1.MyHandler" />
      </handlers>
    </system.webServer>
</configuration>

I then open IIS (IIS 7.0) and I have to right-click on the Test folder under default web site and click convert to application. This makes it a site.

I then go to a browser and i go to http://localhost/Test/

I then get something like this:
fxnjswtkkzs1silahvpf5xun
09:48:52.9194609

If i press F5 or refresh the page, the session id changes.
That is not supposed to happen.

I just cannot figure this out. And the funny thing is it did work yesterday.
Can someone please help....

ps, same behaviour in firefox and ie

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

獨角戲2024-12-22 08:28:37

是的,您每次都应该获得一个新的 SessionID,不仅在您的 GenericHandler 上,而且在简单的 ASPX 页面上除非< /strong> 您访问您的 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"]);
}

Yes you are supposed to get a new SessionID every time, not only on your GenericHandler but also on a simple ASPX page UNLESS you access your Session object. Try this:

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"]);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文