Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# FormsAuthentication不起作用。IsAuthenticated始终返回False_C#_Asp.net_Forms Authentication_Httpcontext_Httpcookie - Fatal编程技术网

C# FormsAuthentication不起作用。IsAuthenticated始终返回False

C# FormsAuthentication不起作用。IsAuthenticated始终返回False,c#,asp.net,forms-authentication,httpcontext,httpcookie,C#,Asp.net,Forms Authentication,Httpcontext,Httpcookie,我正在使用ASP.net开发网站,我想实现基于表单的身份验证。 在web.config中,我使用 <system.web> <authentication mode="Forms" > <forms loginUrl="login.aspx" protection="All" path="/" timeout="30" name=".ASPXFORMSDEMO"> </forms> </authen

我正在使用ASP.net开发网站,我想实现基于表单的身份验证。 在web.config中,我使用

  <system.web>
    <authentication mode="Forms" >
      <forms loginUrl="login.aspx" protection="All" path="/" timeout="30" name=".ASPXFORMSDEMO">
      </forms>
    </authentication>
  </system.web>
我有一个叫post.aspx的页面。我希望此页面仅对经过身份验证的用户可用。因此,在post.aspx页面的页面加载事件中,我使用此代码检查它

  bool isAuthenticated = HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated;

但是上面的代码总是返回false。我做错了什么?

我想你忘了把:

FormsAuthentication.SetAuthCookie(/*UserHere*/ ,false);
FormsAuthentication.SetAuthCookie(/*UserHere*/ ,false);