MVC 站点 - 确保默认条目视图始终正确
我有一个具有 AD 授权的 MVC 站点。这一切工作正常。我将网站发布到网络服务器并直接调用该网站(http://intranet)。如果我有一段时间没有登录(我有一个 30 分钟 TTL 的授权 cookie),系统会提示我登录,如果成功,我将被重定向到 homeController 的索引视图。这很棒并且符合预期。
如果我保持会话打开(浏览器打开)并浏览离开该网站,然后浏览回 http://intranet ,我没有受到挑战,因为我最近已经进行了身份验证,但默认页面来自不同的控制器,而不是主页视图。
我怎样才能阻止这种情况发生?它不可能是会话设置,因为这不是新会话,并且路由显示正确 - 无论如何,此时它们都不会被调用。
请MVC大师指教......!
注册路由块如下:
public static void RegisterRoutes(RouteCollection routes)
{
// standard MVC route regsitration
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"PaginatedTimesheets", // Route name
"{controller}/{action}/{page}/{view}", // URL with parameters
new { controller = "Timesheets", action = "Index", page=0, view=0 } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
I have a MVC site with AD authorization. This is all working fine. I publish the site to the webserver and call the site directly (http://intranet). If I have not logged in for a while (I have an authorised cookie with a 30 minute TTL), I am prompted to log-in and if successful I am redirected to the homeController's index view. This is great and as expected.
If I keep the session open (browser open) and browse away from the site, if I then browse back to http://intranet, I am not challenged as I have recently authenticated but the default page is from a different controller and not the home page view.
How can I stop this from happening? It cannot be a session setting as this is not a new session and the routes appear correct - they are not beng called at this point anyhow.
Please MVC guru's advise....!
Register route block is as follows:
public static void RegisterRoutes(RouteCollection routes)
{
// standard MVC route regsitration
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"PaginatedTimesheets", // Route name
"{controller}/{action}/{page}/{view}", // URL with parameters
new { controller = "Timesheets", action = "Index", page=0, view=0 } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的默认路线是什么样的?它应该转到路由中指定的默认控制器/操作。
What is your default route look like? It should be going to your default controller/action specified in your routes.
通过重定向修复
Fixed with redirect