首页 \ 问答 \ 是否有可能销毁由ASP.NET(VB.NET)用Javascript设置的会话变量?(Is it possible to destroy a session variable set by ASP.NET (VB.NET) with Javascript?)

是否有可能销毁由ASP.NET(VB.NET)用Javascript设置的会话变量?(Is it possible to destroy a session variable set by ASP.NET (VB.NET) with Javascript?)

正如标题所述,我有一个会话变量,在登录脚本中使用asp.net和vb.net代码隐藏进行设置。 我可以在单击链接时调用JavaScript函数来销毁会话变量吗?

如果可能的话,我可以使用jQuery来简化这个过程吗?


As the title states, I have a session variable that is set during a login script with asp.net and vb.net code-behind. Can I call a javascript function when a link is clicked that will destroy that session variable?

If it is possible, can I use jQuery to make that process easier?

更新时间:2022-10-03 07:10

最满意答案

是的,使用$.post("logout.aspx"); 在你的Javascript中,并创建破坏会话的文件logout.aspx。


Yes, use $.post("logout.aspx"); in your Javascript, and create the file logout.aspx that destroys the session.

相关问答

更多
  • 更改值服务器端需要页面的完整帖子或ajax调用。 因此,您可以添加HiddenField并将其值设置为2客户端,然后在服务器端按钮处理程序中使用该值来设置会话变量。 或者您可以对Web服务执行ajax调用。 对于同一点击事件执行客户端和服务器端操作,您可以执行以下操作。 像往常一样添加服务器端Click处理程序,然后使用ClientScriptManager.RegisterOnSubmitStatement注册客户端事件。 以下是MSDN的示例: <%@ Page Language="C#"%>
  • 是的,使用$.post("logout.aspx"); 在你的Javascript中,并创建破坏会话的文件logout.aspx。 Yes, use $.post("logout.aspx"); in your Javascript, and create the file logout.aspx that destroys the session.
  • 如果您在ASP.NET中使用默认会话,则它将存储在ASP.NET工作进程中的内存中。 它是一个服务器端缓存,与客户端无关。 还有其他会话存储选项可用,例如专用会话状态机或sql server。 您也可以推出您自己的会话提供程序。 所有在这里解释http://msdn.microsoft.com/en-us/library/ms972429.aspx If you are using the default session in ASP.NET then it is stored in memory insi ...
  • 在示例中,您提供ASP代码(包含在<%%>中的代码)在页面进入浏览器之前处理,Javascript在浏览器中处理。 如果你想将一个值传递给服务器有很多选项,但一种简单的方法是在表单中使用隐藏的输入( 示例 ),然后提交回服务器,然后当你收到帖子时在服务器上,您将其添加到会话中。 void Page_Load() { //Don't blindly trust input from the client, validate first! Session["Username"] = Reques ...
  • 你可以通过ajax调用页面来设置会话变量,以便随着ajax调用一起发送 请参阅: jQquery Ajax You could do it with a ajax call to a page that sets the session variable of choice to whaterver you send along with the ajax call See: jQquery Ajax
  • 除了womp: 未启用Cookie 在设置会话变量之后立即重定向 我会特别怀疑第二个,特别是如果你使用任何形式的Response.Redirect的urlrewriting机制。 In addition to womp: Not having cookies enabled Redirecting immediately after setting the session variable(s) I would suspect the second one in particular, especially ...
  • 您的标记是错误的,因为Label控件没有DataSourceID属性,因此您应该将其删除: '&' <%# Eval("Last_Name")%>"> 我还将删除Text属性中的Eval表达式(除非它位于数据绑定控件-gridview中,等等),并将其保留为:
    您不能在服务器端代码中使用客户端变量。 您必须将此客户端值发布到服务器(这就是客户端 - 服务器体系结构基本上如何工作)。 也许你可以使用ajax从控制器获取sessionId,如下所示; jQuery的 $.get("SomeController/GetSessionId?userId=" + user.Id, function(result) { var sessionUserId = result.SessionId; }); SomeController.cs public ActionR ...
  • 如果您使用会话来维护整个应用程序中的页面访问权限,则可以在将页面重定向到“LoginPage.aspx”之前使用Session.Clear()和Session.Abondon() 。 我希望这回答了你的问题。 如果是,请将其标记为“已回答”。 If you are using session to maintain your pages access throughout your application, you can use Session.Clear() and Session.Abondon() ...
  • 您在这里混淆了服务器端代码和客户端代码错误的概念: 所有C#代码始终在服务器端执行,即使它位于客户端条件块内。 这意味着你的@{ Session["BrowserName"] = "XX"; } 代码块总是在服务器上执行,而不仅仅是适当的代码块,因为这两个块只是“客户端条件” - 在服务器上它们只是“文本”。 您应该/可以做的是在服务器端评估中转换条件并检查服务器上的用户代理: