0

假设我有一个网站处理用户上传的文件(例如存储或从 sql 表中提取数据)。有没有办法确保一个用户可以打开多个选项卡/浏览器窗口,每个窗口编辑一个不同的文件?

我可以使用会话 ID 作为解决此问题的一种方式吗?我还需要避免像这里提到的超时问题:asp.net cookies, authentication and session timeouts,但据我了解,身份验证票证在同一浏览器的所有选项卡/窗口之间共享。

谢谢

4

3 回答 3

0

哪有这回事。

每个选项卡通常是同一会话的一部分,但浏览器不需要将正在使用的选项卡传递回服务器(没有规范这样做)。

由于网络应该是无状态的,这样做会破坏这个目的。

您可以通过将自己的标识符嵌入其中来识别特定的请求/响应对(标题、隐藏的表单字段等......)。

于 2012-09-14T14:13:03.107 回答
0

为了我的需要,我决定将文件名保存为一个字符串,用于在不同的选项卡/浏览器窗口上进行识别。该字符串使用查询字符串在网页之间传递,我在存储该值的数据库表中添加了一个新列。

对数据库表所做的任何更改都将使用文件名作为过滤器。结果,不同的页面(具有不同的查询字符串)将能够同时处理数据库表而不会相互干扰。

于 2012-09-14T19:01:51.607 回答
0

希望将帮助其他人处理唯一标识符以在服务器端的 ASP.NET 中进行验证。这是我的解决方案

     /// <summary>
/// Page Load event handler 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{


    if (!Page.IsPostBack)
    {            
        //Check if session object has not been assigned - page is being loading first time or session has been expired
        if (Session["ValidateId"] == null)
             Session["ValidateId"] = Session.SessionID;           

    }
    else
    {

        //Check if ViewState has not been previously assigned
        if (ViewState["UniqueId"] == null)
        {

            //Always store ticks when page is being requested through post back
            Int64 numberOfTicks = 0;
            numberOfTicks = DateTime.Now.Ticks;
            //keep this unique id to current page between post backs
            ViewState["UniqueId"] = Session.SessionID + "_" + numberOfTicks.ToString();
        }
    }
}


/// <summary>
/// button click event handler
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCalculate_Click(object sender, EventArgs e)
{


    if (Session["ValidateId"] == null)
    {
        SetAlertMessage("Current Session is Expired. Please reload the page to continue.");
        this.lblValidate.Text = "Current Session is Expired. Please reload the page to continue.";
        return;
    }

    else
    {

        //Assign Unique Id from View State - id is unique across browser windows and belong only to current page
        Session["UniqueId"] = ViewState["UniqueId"];
        //Instantiate object to run some calculation and manipulate records in database
        this._transformerloadParser = new TransformerLoadDataParser(ViewState["UniqueId"].ToString());
    }       
}   


/// <summary>
/// User alert message through ClientScriptManager
/// </summary>
/// <param name="message"></param>
protected void SetAlertMessage(String message)
{
    StringBuilder sb = null;

    String scName = "AlertScript";
    ClientScriptManager csm = Page.ClientScript;
    Type scType = Page.GetType();


    sb = new StringBuilder();
    sb.Append("alert('");
    sb.Append(message);
    sb.Append("')");
    ScriptManager.RegisterStartupScript(this, scType, scName, sb.ToString(), true);
}   

//class logic
public class TransformerLoadDataParser
{
    //Constructor
    public TransformerLoadDataParser(String uniqueId)
    {
        Init(uniqueId);
    }   


    /// <summary>
    /// All required variable initialization
    /// </summary>
    protected void Init(String uniqueId)
    {
        try
        {

                this._userIdentityName = HttpContext.Current.User.Identity.Name;

                if (HttpContext.Current.Session["UniqueId"] == null || !String.Equals(HttpContext.Current.Session["UniqueId"],uniqueId))
                    throw new Exception("UniqueId as Session Key has not been set, expired or not properly set.");

                this._sessionId = uniqueId;

            }
            else
            {
                throw new Exception("Application settings are not defined in web config file.");
            }


        }
        catch (Exception)
        {

            throw;
        }
    }

    //some other logic
}   
于 2013-04-12T18:58:16.563 回答