views:

88

answers:

1

If you have a link to a webpage in a MicroSoft Word document and you follow this link to get to the web page ASP.Net session variables do not always work as expected.

In particular they work the first few times and then later on they stop working.

For instance if you have a link to an MVC Page like:

http://localhost/Home/TransferToWebForm

and in the controller you have:

public ActionResult TransferToWebForm()
{
    Session["SessionVarFromMVC"] = "Some Value";
    return Redirect("~/WebForm.aspx");
}

Then in the target page (WebForm.aspx) you try to retrieve these session variables they are empty.

<%= string.IsNullOrEmpty(Session["SessionVarFromMVC"]) 
    ? "***Session Empty***" 
    : Session["SessionVarFromMVC"] %>

(I discovered in Office 2007 and I'm not sure if the problem exists in other versions)

A: 

The problem is that when you first follow the link from Microsoft Word the server sets a cookie (ASP.NET_SessionId) and word remembers this. Subsequent clicks on the link cause the same cookie to be sent to the server with the new request.

Everything works fine with this process until that session times out on the server. On the next click Word sends the cookie with the request and the server no longer has a valid session for it. In this case the the session variables set by the first page simply fall off the end of the earth (so to speak) and are not available to the next page.

The thing that is puzzling to me is why is Word storing the session cookie?

RonnBlack