在MVC中重定向到会话到期时登录

时间:2016-07-18 05:57:04

标签: session model-view-controller

如何在会话到期时从Global.asax的session_end重定向到Login.cshtml。

Response.redirect()在那里没有工作。

请评论。

1 个答案:

答案 0 :(得分:0)

尝试这可能是您可以检查会话正在进行还是过期

Check this

这里给出答案

check also

这是覆盖ActionFilterAttribute的类。

    let closeAction = UIAlertAction(title: "Close", style: UIAlertActionStyle.Cancel) { (alertAction) -> Void in

    }

    addressAlert.addAction(createRouteAction)
    addressAlert.addAction(closeAction)

    presentViewController(addressAlert, animated: true, completion: nil)
}

然后在操作中添加此属性,如下所示:

     GMSCameraPosition *cameraPosition=[GMSCameraPosition cameraWithLatitude:18.5203 longitude:73.8567 zoom:12];
        _mapView =[GMSMapView mapWithFrame:CGRectZero camera:cameraPosition];
        _mapView.myLocationEnabled=YES;
        GMSMarker *marker=[[GMSMarker alloc]init];
        marker.position=CLLocationCoordinate2DMake(18.5203, 73.8567);
        marker.icon=[UIImage imageNamed:@"aaa.png"] ;
        marker.groundAnchor=CGPointMake(0.5,0.5);
        marker.map=_mapView;
        GMSMutablePath *path = [GMSMutablePath path];   
        [path addCoordinate:CLLocationCoordinate2DMake(@(18.520).doubleValue,@(73.856).doubleValue)];
        [path addCoordinate:CLLocationCoordinate2DMake(@(16.7).doubleValue,@(73.8567).doubleValue)];

        GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];
        rectangle.strokeWidth = 2.f;
        rectangle.map = _mapView;
        self.view=_mapView;

或者只添加属性一次:

  public class SessionExpireAttribute : ActionFilterAttribute
   {
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        HttpContext ctx = HttpContext.Current;
        // check  sessions here
        if( HttpContext.Current.Session["username"] == null ) 
        {
           filterContext.Result = new RedirectResult("~/Login/Index");
           return;
        }
        base.OnActionExecuting(filterContext);
    }
  }