4
我在IAuthorizationFilter中有一些代码将用户重定向到登录页面,但我在更改所使用的控制器时遇到了问题。所以,我可能会做重定向到不同的控制器
public void OnAuthorization(AuthorizationContext context)
{
UserController u = new UserController();
context.Result = u.Login();
context.Cancel = true;
}
但这会导致
The view 'Login' or its master could not be found. The following locations were searched:
~/Views/Product/Login.aspx
~/Views/Product/Login.ascx
~/Views/Shared/Login.aspx
~/Views/Shared/Login.ascx
我从一个产品CONTROLER运行此。我如何让视图引擎使用用户控制器而不是产品控制器?
编辑:我得到了它与
RedirectResult r = new RedirectResult("../User.aspx/Login");
context.Result = r;
context.Cancel = true;
工作,但是这是一个cludge,我敢肯定有一个更好的办法。在ActionFilterAttribute中暴露的很少。看起来好像它可能是有用的,如果暴露在AuthorizationContext中的控制器有RedirectToAction暴露这很容易。
这应该解释它:[ASP.NET MVC提示#2 - 重定向到另一个动作并将信息传递给它] [1] [1]:http://weblogs.asp.net/mikebosch/archive/2008/ 02/02/ASP-净-MVC尖-2-重定向到另一个动作和 - 通过信息到it.aspx – ddc0660 2008-09-21 16:36:58