0
我希望你能帮助我解决这个问题,我正在使用ASP.NET C#开发一个项目,问题是我需要点击一个标签来执行一个Json这会结束会话,因此您必须调用RestartSesion()方法。在asp.net中重启会话c#an json
所有代码都在MasterPage中。
问题是只有警报显示文本''错误; ''。
我告诉你我做了什么。
我有一个VSesion类,有几种方法,但我今天工作的是RestartSesion。
public static void ReiniciarSesion()
{
HttpContext.Current.Session.Abandon();
HttpContext.Current.Response.Redirect(Resources.SitePages.Login);
}
Template.Master.cs调用ReiniciarSesion。
[WebMethod]
public static void ReiniciarSession()
{
VSesion.ReiniciarSesion();
}
Template.Master。这是我的麻烦。
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("#Reiniciar").click("click", function() {
ReiniciarSession();
});
});
function ReiniciarSession() {
$.ajax({
type: "POST",
url: "Template.Master/ReiniciarSession",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus + ": " + XMLHttpRequest.responseText);
}
});
}
</script>
这里是HTML模板:
<ul>
<li>
<a href="#" id="Reiniciar">
<span>Salir</span>
</a>
</li>
</ul>
<script src="JS/jquery.js" type="text/javascript"></script>
<script src="JS/jquery-1.11.3.min.js" type="text/javascript"></script>
我希望你能帮助我。谢谢。!!
两个请求:请只使用英文,并且只能使用代码片段完整的HTML/CSS/Javascript代码,可以在浏览器内工作。对于所有其他类型的代码,使用** {} **按钮,这与使用Ctrl-K相同。 –
@Peter B,我已经编辑过,审查正在审理中,好吗? –
Template.Master/ReiniciarSession不是有效的URL。如果您使用$ .ajax,则Response.Redirect将不起作用。使用[window.location](http://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-page-in-jquery) –