The angularjs application is on my index.cshtml page. When the user first hits the index.cshtml page, if they are not logged in it will redirect them the login page. When they are logged in the system will redirect them to the angular application. The login session expires after 20 minutes. When users login session expies I need the angular application to redirect to the login page just like a regular web application. Is there a way for angular to check the login session/cookie on every action? For example, if a user presses a button or navigates to a different route and the session has expired they should be redirected to the login page.

angularjs应用程序在我的index.cshtml页面上。当用户第一次访问index.cshtml页面时,如果他们未登录,则会将登录页面重定向。登录后,系统会将它们重定向到角度应用程序。登录会话在20分钟后到期。当用户登录会话时,我需要角度应用程序重定向到登录页面,就像常规Web应用程序一样。有没有办法让角度检查每个动作的登录会话/ cookie?例如,如果用户按下按钮或导航到不同的路线并且会话已过期,则应将其重定向到登录页面。

Also, the user must refresh the browser for them to logout and be redirected to the login screen.

此外,用户必须刷新浏览器才能注销并重定向到登录屏幕。

1 个解决方案

#1


2

Assuming your cookie/session is not httpOnly you can poll to check if the cookie/session exists locally (document.cookie), redirecting when your cookie is not found within document.cookie. If you have the httpOnly flag set, you will not be able to see it in document.cookie. You can set a timeout for 20 minutes. Use the AngularJS's http interceptors to clear the timeout when a request is made and then create a new one.

假设您的cookie /会话不是httpOnly,您可以轮询以检查cookie /会话是否存在于本地(document.cookie),当在document.cookie中找不到您的cookie时重定向。如果设置了httpOnly标志,则无法在document.cookie中看到它。您可以将超时设置为20分钟。使用AngularJS的http拦截器在发出请求时清除超时,然后创建一个新的。

更多相关文章

  1. 在Android上使用离子崩溃而不是ios构建的混合应用程序
  2. JavaScript实际应用:父子页面交互
  3. 执行javascript作为coldfusion页面加载
  4. 没有'Access-Control-Allow-Origin'反应表达docker应用程序
  5. 如何测试从实时网站提取数据的AJAX应用程序?
  6. 如何在页面上获得带有javascript的特定单词的链接
  7. 我可以在JavaScript中从不同的页面传递参数吗?
  8. Ajax的实用技术——用户的注意力从页面的其他区域到转移选择的图
  9. 不断更改页面(例如cookie点击器中的cps)

随机推荐

  1. Android 4.0 input touch解析(一)
  2. android自定义布局中的平滑移动
  3. Java讲师与Android讲师通缉令--悬赏2000
  4. Android 开发者必备的十个工具
  5. android 进程之间通信--Android 使用【AI
  6. Android开发中的游戏开发使用View还是Sur
  7. 【Android】android镜像翻转
  8. Android学习07-----事件处理(1)单击事件_
  9. Android 中文 API――android.widget合集
  10. Android中级教程之--------Android应用程