2012-03-09 97 views
0

我是我的註銷操作方法我試圖重定向到web.config中定義的loginurl。asp.net mvc重定向到表單loginurl

我已經試過

public ActionResult LogOff() 
{ 
    if(Request.IsAuthenticated) 
     FormsAuthentication.SignOut(); 

    return RedirectToRoute(FormsAuthentication.LoginUrl); 
} 

但是它返回一個錯誤

名爲「/首頁/索引」的路由不能路線 集合中找到。參數名:名

的配置設置的定義如下

<authentication mode="Forms"> 
    <forms loginUrl="/Home/Index" timeout="2880" /> 
</authentication> 

有一些其他的過載或方法,我應該使用?

+1

相反RedirectToRoute的,你有沒有嘗試過直接回擊重定向? – 2012-03-09 05:30:27

回答

3

RedirectToRoute(string routeName)接受RouteName不是路徑。

使用RedirectToAction

return RedirectToAction("Index", "Home"); 

或者Redirect

return Redirect(FormsAuthentication.LoginUrl);