日期:2014-05-17  浏览次数:20439 次

asp.net mvc4 ajax请求
前提是用户已经退出。用post请求数据源,前台代码如下
JScript code
 
 jQuery(function(){ 
  $.post("account/Getlist",function(data){
 $("#msg").html(data.msg);
})
})



此时我用户退出了,我通过浏览器上面的后退按钮,又返回到此页面,同时页面初始化的加载数据的Ajax请求又发起一次!
C# code


 [AuthorizationFilter]
  public ActionResult Getlist()



AuthorizationFilter实现如下,过滤实现的代码如下:
C# code

public class AuthorizationFilter : ActionFilterAttribute {
 public override void OnActionExecuting(ActionExecutingContext filterContext) {
 if (filterContext.HttpContext.Request.IsAjaxRequest()) { 
if (filterContext.HttpContext.Session["User"] == null) {
 filterContext.Result = new RedirectResult("/user/user/login");
 //我想实现如果用户没有登录 转到登录 页页 这里的代码应该怎么写。。 
//Ajax请求无法实现转向
 }
 }
 }
 } 




请问ajax请求时,,没有验证通过 。。怎么在后台实现页面转向。。转到登录页面


和这一个帖子极像,求解决方案

http://topic.csdn.net/u/20120301/12/6339133e-e1e1-48be-9733-5afa5231ddc6.html


------解决方案--------------------
那么你应该将这段代码改下:
$("#msg").html(data.msg);
假如用户处于在线状态,那么你这里输出的data.msg值的头部应该包含一个值(比如说1),表示 用户在线

每次抓的时候如果这里的值不包含1,那么,在此处就应该进行跳转了。
------解决方案--------------------
$("#msg").html(data.msg);
这里你应该加上一个判断,判断用户是否在线
即data.msg值里应该有个标记,表示这个用户在线,如果不在线,就应该进行跳转..
------解决方案--------------------
那可以使用cookie进行判断,在客户端通过js调用cookie
------解决方案--------------------
探讨

有缓存的!

现在用这个方式处理了
HTML code

@{
Response.Expires = -1;
Response.AddHeader("pragma", "no-cache");
Response.AddHeader("cache-control", "no-cache");
Response.CacheControl = "no-cache";
Response.Cac……