.NET 表单身份验证不起作用

发布于 2024-10-24 04:07:05 字数 2216 浏览 2 评论 0原文

我的 .NET 应用程序存在问题,有时只能在客户端位置重现该问题,这使得解决起来非常困难。在应用程序中使用表单身份验证。每个匿名用户都会被重定向到一个登录页面。用户输入用户名和密码后,它会重定向到 DefaultURL 或某个预定义的页面。问题是,有时当用户输入正确的用户名和密码时,它不会登录,而是刷新登录页面,没有任何错误消息。多次尝试输入用户名和密码后,用户可以登录系统。

请参阅我的登录页面 Submit_Click 下面的代码:

    Dim userName As String = tbUsername.Text
    Dim password As String = tbPassword.Text
    Dim returnUrl As String = Request("returnUrl")

    If IsValidated() Then
        FormsAuth.SignIn(userName, False)

        If password = WebConfigurationManager.AppSettings("PasswordDefault") Then
            FlashMessage.ErrorMessage("You have default password """ & password & """. Please change it")
            Response.Redirect("~/ChangePassword.aspx")
        End If
        If Not String.IsNullOrEmpty(returnUrl) Then
            Response.Redirect(returnUrl)
        Else
            If Roles.IsUserInRole(userName, Constants.SOME_ROLE) Then
                Response.Redirect("~/Forms/SomePage.aspx")
            Else
                Response.Redirect("~/Default.aspx")
            End If
        End If
    Else

    End If

更新:
我检查了Windows事件查看器,它有以下事件:

事件类型:信息
事件来源:ASP.NET 2.0.50727.0
活动类别:网络活动
事件 ID:1315
日期:2010年4月29日
时间:上午 11:55:56
用户:不适用
计算机:TWDWEB1
描述:
活动代码:4006
事件消息:会员凭据验证失败。
活动时间:2010年4月29日 11:55:56 AM
活动时间(UTC):2010年4月29日下午3:55:56
事件 ID:9e5aea5a6d6b4f7a96fc38a334d181dd
事件序列:26
事件发生:4
活动详情代码:0

申请信息:
应用程序域:/LM/W3SVC/1/Root/DataManipulationsService-1-129170192766483624
信任级别:完全
应用程序虚拟路径:/DataManipulationsService
应用程序路径:F:\Development\DataManipulationsService\
机器名称:TWDWEB1

进程信息:
进程 ID:7948
进程名称:w3wp.exe
帐户名:NT AUTHORITY\NETWORK SERVICE

请求信息:
请求网址:
请求路径:
用户主机地址:
用户:
已验证:错误
身份验证类型:
线程帐户名称:NT AUTHORITY\NETWORK SERVICE

要验证的名称:xxxxxx

自定义事件详细信息:

有关详细信息,请参阅帮助和支持中心:http://go.microsoft.com/ fwlink/events.asp

I have an issue with my .NET application and it can only be reproduced sometimes and only on client's location, which makes it extremely difficult to resolve. In the application the forms authentication is used. There is a login page to which every anonymous user is redirected. After user enters username and password, it redirects to DefaultURL or some predefined page. The problem is that sometimes when user enters correct username and password, it doesn't login, instead it just refreshes the login page without any error messages. After several tries of inputing username and password, user is able to login to the system.

See my login page Submit_Click code below:

    Dim userName As String = tbUsername.Text
    Dim password As String = tbPassword.Text
    Dim returnUrl As String = Request("returnUrl")

    If IsValidated() Then
        FormsAuth.SignIn(userName, False)

        If password = WebConfigurationManager.AppSettings("PasswordDefault") Then
            FlashMessage.ErrorMessage("You have default password """ & password & """. Please change it")
            Response.Redirect("~/ChangePassword.aspx")
        End If
        If Not String.IsNullOrEmpty(returnUrl) Then
            Response.Redirect(returnUrl)
        Else
            If Roles.IsUserInRole(userName, Constants.SOME_ROLE) Then
                Response.Redirect("~/Forms/SomePage.aspx")
            Else
                Response.Redirect("~/Default.aspx")
            End If
        End If
    Else

    End If

UPDATE:
I checked the windows Event Viewer and it has the following events:

Event Type: Information
Event Source: ASP.NET 2.0.50727.0
Event Category: Web Event
Event ID: 1315
Date: 4/29/2010
Time: 11:55:56 AM
User: N/A
Computer: TWDWEB1
Description:
Event code: 4006
Event message: Membership credential verification failed.
Event time: 4/29/2010 11:55:56 AM
Event time (UTC): 4/29/2010 3:55:56 PM
Event ID: 9e5aea5a6d6b4f7a96fc38a334d181dd
Event sequence: 26
Event occurrence: 4
Event detail code: 0

Application information:
Application domain: /LM/W3SVC/1/Root/DataManipulationsService-1-129170192766483624
Trust level: Full
Application Virtual Path: /DataManipulationsService
Application Path: F:\Development\DataManipulationsService\
Machine name: TWDWEB1

Process information:
Process ID: 7948
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE

Request information:
Request URL:
Request path:
User host address:
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE

Name to authenticate: xxxxxx

Custom event details:

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧梦荧光笔 2024-10-31 04:07:06

在signin() 调用周围添加一个try/catch 块。如果该调用由于客户端系统上的某些配置错误而失败,您可以向用户或日志公开该错误。也许代码正在执行任何可能隐藏错误的异常处理?

Add a try/catch block around the signin() call. If that call is failing due to some misconfiguration on your client's system, you can expose the error to the user or log. Perhaps is the code doing any exception handling that could be burying the error?

三生殊途 2024-10-31 04:07:05

“客户位置”是什么意思?您的意思是从客户端的计算机登录(与从其他地方登录到同一网络服务器)还是说他们拥有自己的网站副本?

在不知道这个问题的答案的情况下,我建议的第一件事是,如果您从网络场运行,则需要确保 web.config 文件中的 machineKey 元素已设置并且在网络场中的每台服务器上都是相同的。

What do you mean by "client location". Do you mean logging in from the client's machine (to the same web server as you would from any place else) or do you mean that they have their own copy of the website?

Without knowing the answer to that question, the first thing I would suggest is that if you're running from a web farm, you need to ensure that the machineKey element in the web.config file is set and is identical on each of the servers in the web farm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文