为什么在点击 MS Word 文档中的链接时会话变量无法正常工作

发布于 2024-08-02 12:43:17 字数 644 浏览 1 评论 0原文

如果 Microsoft Word 文档中有指向网页的链接,并且您通过此链接访问该网页,则 ​​ASP.Net 会话变量并不总是按预期工作。

特别是他们在前几次工作,然后就停止工作。

例如,如果您有一个指向 MVC 页面的链接,例如:

http://localhost/Home/TransferToWebForm

并且在控制器中您有:

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

然后在目标页面 (WebForm.aspx) 中您尝试检索这些会话变量,它们是空的。

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

(我是在Office 2007中发现的,不确定其他版本是否也存在该问题)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幻梦 2024-08-09 12:43:17

问题是,当您第一次点击 Microsoft Word 中的链接时,服务器会设置一个 cookie (ASP.NET_SessionId),并且 Word 会记住它。随后单击该链接会导致将相同的 cookie 与新请求一起发送到服务器。

此过程一切正常,直到该会话在服务器上超时。下次单击时,Word 将随请求发送 cookie,并且服务器不再具有有效的会话。在这种情况下,第一页设置的会话变量只是从地球的尽头消失(可以这么说)并且不可用于下一页。

让我感到困惑的是为什么 Word 存储会话 cookie?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文