简体   繁体   English

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

[英].NET forms authentication doesn't work

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. 我的.NET应用程序有问题,它有时只能在客户端的位置复制,因此很难解决。 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. 用户输入用户名和密码后,它将重定向到DefaultURL或某些预定义页面。 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: 请参阅下面的登录页面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

UPDATE: 更新:
I checked the windows Event Viewer and it has the following events: 我检查了Windows事件查看器,它具有以下事件:

Event Type: Information 事件类型:信息
Event Source: ASP.NET 2.0.50727.0 事件源:ASP.NET 2.0.50727.0
Event Category: Web Event 活动类别:网络活动
Event ID: 1315 事件ID:1315
Date: 4/29/2010 日期:2010年4月29日
Time: 11:55:56 AM 时间:11:55:56 AM
User: N/A 用户:N / A
Computer: TWDWEB1 电脑:TWDWEB1
Description: 描述:
Event code: 4006 场次编码:4006
Event message: Membership credential verification failed. 事件消息:成员资格凭证验证失败。
Event time: 4/29/2010 11:55:56 AM 活动时间:2010/4/29上午11:55:56
Event time (UTC): 4/29/2010 3:55:56 PM 活动时间(UTC):2010/4/29下午3:55:56
Event ID: 9e5aea5a6d6b4f7a96fc38a334d181dd 事件ID:9e5aea5a6d6b4f7a96fc38a334d181dd
Event sequence: 26 事件顺序:26
Event occurrence: 4 事件发生:4
Event detail code: 0 事件详细代码:0

Application information: 应用信息:
Application domain: /LM/W3SVC/1/Root/DataManipulationsService-1-129170192766483624 应用程序域:/ LM / W3SVC / 1 / Root / DataManipulationsService-1-129170192766483624
Trust level: Full 信任等级:完整
Application Virtual Path: /DataManipulationsService 应用程序虚拟路径:/ DataManipulationsService
Application Path: F:\\Development\\DataManipulationsService\\ 应用程序路径:F:\\ Development \\ DataManipulationsService \\
Machine name: TWDWEB1 机器名称:TWDWEB1

Process information: 处理信息:
Process ID: 7948 进程ID:7948
Process name: w3wp.exe 进程名称:w3wp.exe
Account name: NT AUTHORITY\\NETWORK SERVICE 帐户名称: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 线程帐户名称:NT AUTHORITY \\ NETWORK SERVICE

Name to authenticate: xxxxxx 身份验证名称:xxxxxx

Custom event details: 自定义事件详细信息:

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp . 有关更多信息,请参阅位于http://go.microsoft.com/fwlink/events.asp的“帮助和支持中心”。

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? 您是要从客户端计算机登录(与从任何其他位置登录到同一Web服务器),还是要他们拥有自己的网站副本?

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

Add a try/catch block around the signin() call. 在signin()调用周围添加一个try / catch块。 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? 也许代码正在执行任何可能掩埋错误的异常处理?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM