从会话ID获取会话对象在ASP.Net [英] Get session object from sessionID in ASP.Net

查看:135
本文介绍了从会话ID获取会话对象在ASP.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反正有从一个会话对象的的SessionID

Is there anyway to get a session object from a sessionID?

我使用的是Flash上​​传,让用户上传自己的文件到服务器的小项目,但问题是Flash发送会话和饼干时,有一些错误(Firefox或Chrome,而不是IE),所以我发现了一个解决方案来解决这个问题:发送的SessionID 通过Flash到服务器,并在服务器上,德code 的SessionID 回会话对象,但我不如何做到这一点。我使用ASP.NET和C#。

I have a small project using a Flash upload to let a user upload their file to the server, but the problem is that Flash has some error when sending the session and cookie (in Firefox or Chrome, but not IE), so I found a solution to fix this problem: sending the sessionID through Flash to the server, and on the server, decode sessionID back to the session object, but I don't how to do it. I'm using ASP.NET and C#.

谁能告诉我该怎么做?

推荐答案

由武果汁提出的链接不再工作。

The link proposed by Moo-Juice is no longer working.

我以前在此页面中提供的code:

I used the code provided in this page:

http://snipplr.com/view/15180/

它的工作就像一个魅力。

It worked like a charm.

如果该链接将变得坏了,这里是code:

If the link would become broken, here is the code:

void Application_BeginRequest(object sender, EventArgs e)
{
    try
    {
        string session_param_name = "ASPSESSID";
        string session_cookie_name = "ASP.NET_SESSIONID";
        string session_value = Request.Form[session_param_name] ?? Request.QueryString[session_param_name];
        if (session_value != null) { UpdateCookie(session_cookie_name, session_value); }
    }
    catch (Exception) { }

    try
    {
        string auth_param_name = "AUTHID";
        string auth_cookie_name = FormsAuthentication.FormsCookieName;
        string auth_value = Request.Form[auth_param_name] ?? Request.QueryString[auth_param_name];

        if (auth_value != null) { UpdateCookie(auth_cookie_name, auth_value); }
    }
    catch (Exception) { }
}
void UpdateCookie(string cookie_name, string cookie_value)
{
    HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
    if (cookie == null)
    {
        HttpCookie cookie1 = new HttpCookie(cookie_name, cookie_value);
        Response.Cookies.Add(cookie1);
    }
    else
    {
        cookie.Value = cookie_value;
        HttpContext.Current.Request.Cookies.Set(cookie);
    }
}

这篇关于从会话ID获取会话对象在ASP.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆