问题ASP.NET验证 [英] Problem with ASP.NET Authentication

查看:85
本文介绍了问题ASP.NET验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与我们的登录程序的问题。

一些客户抱怨说,他们无法登录。我可以在我们的日志中看到,他们的登录成功,他们是从登录页面会员区重定向。但不知何故有没有检测登录,他们被退回到登录页面。

我问客户是否饼干的支持(http://www.html-kit.com/tool​​s/cookietester/),但即使这个测试返回true,问题仍然存在。

这是如何,我实现了登录过程(simplyfied):

 保护无效登录(字符串email,字符串密码)
{FormsAuthentication.SignOut();
GUID的clientId = / *验证通过检查电子邮件地址和密码登录,如果失败则显示错误,否则得到的客户端ID * /
FormsAuthentication.SetAuthCookie(clientId.ToString(),TRUE);HttpContext.Current.Response.Redirect(〜/ Members.aspx);
}

在成员页面通过我在Page_Load中功能检查验证:

 公共静态无效IsAuthenticated()
{
 如果(!HttpContext.Current.User.Identity.IsAuthenticated)
 {
         HttpContext.Current.Response.Redirect(〜/的Login.aspx,真正的);
 }
}

也许我使用FormsAuthentication完全错了?

我问过这之前,但仍然没能想出解决办法,我AP preciate任何帮助。

这是我的web.config:

 <&的System.Web GT;
    <编译调试=假>
      <&集会GT;
       ...
      < /组件>
    < /编译>
    <身份验证模式=表格/>
    <的sessionState模式=是InProc无Cookie =假超时=180/>
    <的customErrors模式=ON/>
    <&HttpHandlers的GT;
    ...
    < / HttpHandlers的>
    <&的HttpModules GT;
    ...
    < /&的HttpModules GT; < /system.web>


解决方案

公共静态无效IsAuthenticated()
{
 如果(!HttpContext.Current.User.Identity.IsAuthenticated)
 {
         HttpContext.Current.Response.Redirect(〜/的Login.aspx,真正的);
 }
}

是没有必要的,当您使用窗体身份验证。

当您指定在web.config中的窗体身份验证(其中还指定登录页面)

 <身份验证模式=表格>
  <形式loginUrl =/授权/登录超时=60/>
< /认证>

和你拒绝所有非athenticated用户的访问

 <授权>
          <拒绝用户=? />
      < /授权>

你没有检查用户自己的认证,该框架需要的照顾。

我会放在 FormsAuthentication.SignOut(); code后面的注销链接

I'm having problem with our login procedure.

Some customers complain that they can't login. I can see in our logs that their login is successful and that they are redirected from the login page to the member area. But there somehow the login isn't detected and they are bounced back to the login page.

I've asked customers to check if cookies are supported (http://www.html-kit.com/tools/cookietester/) but problem remains even if this test returns true.

This is how I've implemented the login procedure (simplyfied):

protected void Login(string email, string password)
{

FormsAuthentication.SignOut();


Guid clientId = /* Validate login by checking email and password, if fails display error otherwise get client id */


FormsAuthentication.SetAuthCookie(clientId.ToString(), true);

HttpContext.Current.Response.Redirect("~/Members.aspx");


}

On the member page I check for authentication by in Page_Load function:

public static void IsAuthenticated()
{
 if (!HttpContext.Current.User.Identity.IsAuthenticated)
 {
         HttpContext.Current.Response.Redirect("~/Login.aspx", true);
 }
}

Maybe I'm using FormsAuthentication completely wrong?

I've asked this before but still haven't been able to figure this out, I'd appreciate any help.

From my Web.Config:

<system.web>
    <compilation debug="false">
      <assemblies>
       ...
      </assemblies>
    </compilation>
    <authentication mode="Forms"/>
    <sessionState mode="InProc" cookieless="false" timeout="180"/>
    <customErrors mode="On"/>
    <httpHandlers>
    ...
    </httpHandlers>
    <httpModules>
    ...
    </httpModules>   </system.web>

解决方案

public static void IsAuthenticated() { if (!HttpContext.Current.User.Identity.IsAuthenticated) { HttpContext.Current.Response.Redirect("~/Login.aspx", true); } }

is not necessary when you use forms authentication.

When you specify the forms authentication in the web.config (in which you also specify the login page)

<authentication mode="Forms">
  <forms loginUrl="/Authorization/Login" timeout="60" />
</authentication>

and you deny all non-athenticated users access

<authorization>
          <deny users="?" />
      </authorization>

you don't have to check the authentication of a user yourself, the framework takes care of that.

I would place the FormsAuthentication.SignOut(); code behind a 'logout' link

这篇关于问题ASP.NET验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆