在我的web.config文件中,我有以下代码:
<system.web>
<authentication mode="Forms">
<forms loginUrl="/Account/Login" slidingExpiration="true" timeout="1" />
</authentication>
<sessionState timeout="1"></sessionState>
</system.web>
我有主页Project,并且会有子页面。我为每个视图索引方法提供了[Authorize]
属性。
会话完成后,当我们选择任何视图时,项目主页面内的页面将重定向。但我希望整个页面被重定向。
感谢任何帮助。
答案 0 :(得分:0)
您的web.config应如下所示。
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
</system.web>
<authentication>
元素应位于<system.web>
下,而不是<assemblies>
。你正在做的其他事情是正确的,即将[Authorize]
属性放在方法/动作上。
当会话到期并且对该操作发出请求时,将使用loginUrl并将用户重定向到登录页面。希望这会有所帮助。