Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 返回按钮后mvc注销它重定向到主页_C#_Asp.net Mvc - Fatal编程技术网

C# 返回按钮后mvc注销它重定向到主页

C# 返回按钮后mvc注销它重定向到主页,c#,asp.net-mvc,C#,Asp.net Mvc,问题在于,按下“注销返回”按钮后,它不会重定向到登录页面。 我读了很多东西,也尝试了很多解决方法 目前的情况如下 在Global.asax文件中 我添加了以下代码 protected void Application_BeginRequest() { Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));

问题在于,按下“注销返回”按钮后,它不会重定向到登录页面。 我读了很多东西,也尝试了很多解决方法

目前的情况如下

Global.asax文件中

我添加了以下代码

protected void Application_BeginRequest()
{
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
    Response.Cache.SetNoStore();
}
In_Layout.cshtml

我打电话

function logout()
{
    window.location.href = '/account/logout';
}
在accountController.cs中

public ActionResult logout()
{
    FormsAuthentication.SignOut();
    System.Web.HttpContext.Current.Session.Abandon(); // it will clear the session at the end of request
    System.Web.HttpContext.Current.Session.Clear();
    System.Web.HttpContext.Current.Session.RemoveAll();

    return RedirectToAction("login", "account");
}
当我按下后退按钮时 它调用
commonController

[SessionAuthorize]
[HttpPost]
public JsonResult getMenu()
{
    masterReturn objmasterReturn = new masterReturn();

    var client = new RestClient(string.Format("{0}/userMenu/getMenu", applicationTitle));
    var request = new RestRequest(Method.POST);
    request.AddHeader("authorization", "bearer " + Session["accessToken"].ToString() + "");
    IRestResponse response = client.Execute(request);
    if (response.StatusCode.ToString().ToLower() == "ok")
    {
        objmasterReturn.success = "true";
        //var details = JObject.Parse(response.Content);
        //dynamic item = JsonConvert.DeserializeObject<masterReturn>(response.Content);
        //objmasterReturn.objectVal = item.objectVal;
        objmasterReturn.objectVal = response.Content;
    }
    else
    {
        objmasterReturn.success = "false";
        objmasterReturn.error = "error in api call !!!";
    }

    return Json(objmasterReturn);
}
下面这行有问题吗

filterContext.Result = new RedirectResult("~/account/logout");
我试过了

filterContext.Result = new RedirectResult("/account/login");
但它不会重定向到登录页面

还有其他工作选项吗?

而不是使用

 filterContext.Result = new RedirectResult("~/account/logout");
像这样使用,我希望这能解决你的问题

 filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "You Controller Name" }, { "action", "ActionMethod Name" } });

您是否使用自定义actionfilter?我使用了auth 2.0进程
 filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "You Controller Name" }, { "action", "ActionMethod Name" } });