我刚刚发现ASP中的每个请求。网络web应用程序在请求开始时获得一个会话锁,然后在请求结束时释放它!

如果你不明白这其中的含义,就像我一开始一样,这基本上意味着:

Any time an ASP.Net webpage is taking a long time to load (maybe due to a slow database call or whatever), and the user decides they want to navigate to a different page because they are tired of waiting, they can't! The ASP.Net session lock forces the new page request to wait until the original request has finished its painfully slow load. Arrrgh. Anytime an UpdatePanel is loading slowly, and the user decides to navigate to a different page before the UpdatePanel has finished updating... they can't! The ASP.Net session lock forces the new page request to wait until the original request has finished its painfully slow load. Double Arrrgh!

那么有什么选择呢?到目前为止,我想出了:

Implement a Custom SessionStateDataStore, which ASP.Net supports. I haven't found too many out there to copy, and it seems kind of high risk and easy to mess up. Keep track of all requests in progress, and if a request comes in from the same user, cancel the original request. Seems kind of extreme, but it would work (I think). Don't use Session! When I need some kind of state for the user, I could just use Cache instead, and key items on the authenticated username, or some such thing. Again seems kind of extreme.

我真不敢相信ASP。Net微软团队在4.0版本的框架中留下了如此巨大的性能瓶颈!我是不是遗漏了什么明显的东西?为会话使用ThreadSafe集合有多难?

我想知道粘性会话和非粘性会话之间的区别。我从网上读到的是:

粘性:只有一个会话对象将在那里。

非会话保持:每个服务器节点的会话对象

我的web应用程序使用会话存储关于用户的信息,一旦他们登录,并维护这些信息,因为他们在应用程序内从页面到页面。在这个特定的应用程序中,我存储的人的user_id, first_name和last_name。

我想在登录时提供一个“让我登录”选项,在用户的机器上放置一个cookie,为期两周,当他们返回应用程序时,将以相同的细节重新启动他们的会话。

做这件事的最佳方法是什么?我不想在cookie中存储他们的user_id,因为这似乎会让一个用户很容易尝试和伪造另一个用户的身份。

在通过$.ajax()登录到一个网站后,我试图向该网站发送第二个$.ajax()请求-但当我检查使用FireBug发送的报头时,请求中没有会话cookie。

我做错了什么?

我读到用cURL发送cookie有用,但不适合我。

我有一个这样的REST端点:

class LoginResource(restful.Resource):
    def get(self):
        print(session)
        if 'USER_TOKEN' in session:
            return 'OK'
        return 'not authorized', 401

当我尝试访问端点时,它拒绝:

curl -v -b ~/Downloads/cookies.txt -c ~/Downloads/cookies.txt http://127.0.0.1:5000/
* About to connect() to 127.0.0.1 port 5000 (#0)
*   Trying 127.0.0.1...
* connected
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.27.0
> Host: 127.0.0.1:5000
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 401 UNAUTHORIZED
< Content-Type: application/json
< Content-Length: 16
< Server: Werkzeug/0.8.3 Python/2.7.2
< Date: Sun, 14 Apr 2013 04:45:45 GMT
<
* Closing connection #0
"not authorized"%

我的~/Downloads/cookies.txt是:

cat ~/Downloads/cookies.txt
USER_TOKEN=in

服务器什么也收不到:

127.0.0.1 - - [13/Apr/2013 21:43:52] "GET / HTTP/1.1" 401 -
127.0.0.1 - - [13/Apr/2013 21:45:30] "GET / HTTP/1.1" 401 -
<SecureCookieSession {}>
<SecureCookieSession {}>
127.0.0.1 - - [13/Apr/2013 21:45:45] "GET / HTTP/1.1" 401 -

我错过了什么?

根据我在Vim的任务,我有几个选项卡打开。

如何保存不同的会话以供以后使用?

我刚刚开始学习web应用程序开发,使用python。我遇到了术语“cookie”和“会话”。我理解cookie,因为它们在浏览器上的键值对中存储了一些信息。但是关于会话,我有一点困惑,在会话中,我们也将数据存储在用户浏览器的cookie中。

例如,我使用用户名='rasmus'和密码='default'登录。在这种情况下,数据将被发布到服务器,它应该检查和登录我,如果认证。然而,在整个过程中,服务器也会生成一个会话ID,它将存储在浏览器的cookie中。现在,服务器还将这个会话ID存储在其文件系统或数据存储中。

但是仅仅基于会话ID,它如何能够在我随后遍历站点时知道我的用户名呢?它是否将服务器上的数据存储为字典,其中键将是会话ID和详细信息,如用户名,电子邮件等是值?

我有点困惑了。需要帮助。

我有一个PHP文件,有时从一个已经开始会话的页面调用,有时从一个没有会话启动的页面调用。因此,当我在这个脚本上有session_start()时,我有时会得到“会话已经开始”的错误消息。为此,我写了以下几行:

if(!isset($_COOKIE["PHPSESSID"]))
{
  session_start();
}

但这次我收到了警告信息:

注意:未定义变量:_SESSION

是否有更好的方法来检查会话是否已经开始?

如果我使用@session_start,它会使事情正常工作,只是关闭警告?

在RESTful API中使用会话真的违反了RESTful吗?我已经看到了许多意见,但我不相信会议是不安宁的。在我看来:

rest不禁止身份验证(否则在RESTful服务中几乎没有用处) 身份验证是通过在请求中发送一个身份验证令牌来完成的,通常是头 这个身份验证令牌需要以某种方式获得,并且可能会被撤销,在这种情况下需要更新 身份验证令牌需要由服务器验证(否则就不是身份验证)

那么会话是如何违背这一点的呢?

客户端,会话是使用cookie实现的 cookie只是一个额外的HTTP报头 会话cookie可以在任何时候获得和撤销 如果需要,会话cookie可以有无限的生存时间 会话id(身份验证令牌)在服务器端得到验证

As such, to the client, a session cookie is exactly the same as any other HTTP header based authentication mechanism, except that it uses the Cookie header instead of the Authorization or some other proprietary header. If there was no session attached to the cookie value server-side, why would that make a difference? The server side implementation does not need to concern the client as long as the server behaves RESTful. As such, cookies by themselves should not make an API RESTless, and sessions are simply cookies to the client.

我的假设错了吗?是什么使会话cookie不安分?

对于我正在从事的一个新的node.js项目,我正在考虑从基于cookie的会话方法(我的意思是,将id存储到用户浏览器中包含用户会话的键值存储中)切换到使用JSON Web Tokens (jwt)的基于令牌的会话方法(没有键值存储)。

这个项目是一个利用socket的游戏。IO——在一个会话(web和socket.io)中有多个通信通道的情况下,有一个基于令牌的会话会很有用。

如何使用jwt方法从服务器提供令牌/会话失效?

我还想了解使用这种范例应该注意哪些常见的(或不常见的)陷阱/攻击。例如,如果这种模式容易受到与基于会话存储/cookie的方法相同/不同类型的攻击。

所以,假设我有以下内容(改编自this和this):

会话存储登录:

app.get('/login', function(request, response) {
    var user = {username: request.body.username, password: request.body.password };
    // Validate somehow
    validate(user, function(isValid, profile) {
        // Create session token
        var token= createSessionToken();

        // Add to a key-value database
        KeyValueStore.add({token: {userid: profile.id, expiresInMinutes: 60}});

        // The client should save this session token in a cookie
        response.json({sessionToken: token});
    });
}

口令登录:

var jwt = require('jsonwebtoken');
app.get('/login', function(request, response) {
    var user = {username: request.body.username, password: request.body.password };
    // Validate somehow
    validate(user, function(isValid, profile) {
        var token = jwt.sign(profile, 'My Super Secret', {expiresInMinutes: 60});
        response.json({token: token});
    });
}

--

会话存储方法的注销(或失效)需要更新KeyValueStore 使用指定的令牌创建数据库。

在基于令牌的方法中似乎不存在这样的机制,因为令牌本身将包含通常存在于键值存储中的信息。