Why are session variables not working as expected by following the link from MS Word document

If you have a link to a web page in a MicroSoft Word document and you follow this link to go to the web page ASP.Net Session Variables do not always work as expected.

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

For example, 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 on the landing page (WebForm.aspx) you try to get these session variables, they are empty.

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

      

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

+2


source to share


1 answer


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

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



What is puzzling me is why does Word store a session cookie?

+1


source







All Articles