1

Suppose I have a website that processes files uploaded by the user (e.g. storing or pulling data from a sql table). Is there a way to ensure that one user can have multiple tabs/browser windows open with each editing a different file?

Could I use session ID as a way of resolving this issue? I also need to avoid timeout issues like what is mentioned here: asp.net cookies, authentication and session timeouts, but authentication tickets are shared across all tabs/windows of the same browser, as I understand it.

Thanks

Community
  • 1
  • 1
Tony
  • 1,839
  • 10
  • 27
  • 48

3 Answers3

1

There is no such thing.

Each tab will normally be part of the same session, but the browser is not required to pass what tab is being used back to the server (there is no specification to do so).

Since the web is supposed to be stateless, doing so would defeat that purpose.

You could identify a specific request/response pair by embedding your own identifier into it (headers, hidden form fields etc...).

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • If I use an identifier such as a header, will I need to retrieve the header when navigating to a different page and then updating the header of that page? – Tony Sep 14 '12 at 14:43
  • @Tony - I don't know what you mean. – Oded Sep 14 '12 at 14:51
0

For my needs, I decided on saving the filename as a string to be used for identification on different tabs/browser windows. The string gets passed along between web pages using querystring and I added a new column to the database table which stores this value.

Any changes being made to the database table will use the filename as a filter. As a result, different pages (with different querystrings) will be able to simultaneously work with the database table without interfering with each other.

Tony
  • 1,839
  • 10
  • 27
  • 48
0

Hope will help other people to deal with unique identifier to validate in ASP.NET on server side. Here is my solution

     /// <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
}   
Serghei T
  • 11
  • 2