How to check if the user is already logged in or not using Cookie?

Deadly 提交于 2019-12-30 07:15:13

问题


I want to know how can I detect if the user is already logged in or not? using a cookie. I am not using any log-in control. I have a db which checks the ID and PWD. Also pls let me know if it can be done without using cookies. Any code or links will help. web.config:

  <authentication mode="Forms">
  <forms name="myForm" loginUrl="LogIn.aspx" path="/" defaultUrl="Home.aspx">
</forms>
  </authentication>
<authorization>
  <deny users="?"/>
   </authorization>

Thanks


回答1:


In asp.net using windows / forms authentication you can tell if the user is logged in via :

<%
   Page.User.Identity.IsAuthenticated
%>

Forms Authentication is cookie based, but can be configured to not use cookies with the cookieless setting.

How to fully setup forms authentication is not a quick answer but it is relatively easy to setup there are many HOW-TO's online. Here is a good one http://www.4guysfromrolla.com/webtech/110701-1.shtml

MSDN :http://msdn.microsoft.com/en-us/library/aa480476.aspx

You can use Windows Authentication also which does not use cookies.




回答2:


I used:

HttpContext.Current.Request.IsAuthenticated


来源:https://stackoverflow.com/questions/833786/how-to-check-if-the-user-is-already-logged-in-or-not-using-cookie

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!