2012-03-09 92 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);