如何更改为公开

发布于 2024-11-05 14:35:07 字数 1064 浏览 4 评论 0原文

Public Sub mainlogin_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles mainlogin.Authenticate
    'Are the credentials valid?
    If Membership.ValidateUser(mainlogin.UserName, mainlogin.Password) Then
        'Has the password expired?
        Dim usrInfo As MembershipUser = Membership.GetUser(mainlogin.UserName)

        Dim daysSincePwdChange As Integer = Convert.ToInt32(DateTime.Now.Subtract(usrInfo.LastPasswordChangedDate).TotalDays)
        If daysSincePwdChange > SecurityUtils.DefaultPasswordExpiryInDays Then
            'Password expired, send user to change password
            Response.Redirect("~/ChangePassword.aspx?UserName=" & Server.UrlEncode(mainlogin.UserName))
        Else
            e.Authenticated = True 'Credentials valid & password is current
        End If
    Else
        e.Authenticated = False    'Invalid!
    End If
end sub

但我得到了这个错误

错误 6“System.Web.SecurityUtils”在此上下文中无法访问,因为它是“Friend”。

Public Sub mainlogin_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles mainlogin.Authenticate
    'Are the credentials valid?
    If Membership.ValidateUser(mainlogin.UserName, mainlogin.Password) Then
        'Has the password expired?
        Dim usrInfo As MembershipUser = Membership.GetUser(mainlogin.UserName)

        Dim daysSincePwdChange As Integer = Convert.ToInt32(DateTime.Now.Subtract(usrInfo.LastPasswordChangedDate).TotalDays)
        If daysSincePwdChange > SecurityUtils.DefaultPasswordExpiryInDays Then
            'Password expired, send user to change password
            Response.Redirect("~/ChangePassword.aspx?UserName=" & Server.UrlEncode(mainlogin.UserName))
        Else
            e.Authenticated = True 'Credentials valid & password is current
        End If
    Else
        e.Authenticated = False    'Invalid!
    End If
end sub

but I got this error

Error 6 'System.Web.SecurityUtils' is not accessible in this context because it is 'Friend'.

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

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

发布评论

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

评论(1

诠释孤独 2024-11-12 14:35:07

你不能 - 正如它所说,System.Web.SecurityUtils 无法访问。您不能将其公开 - 它设计不是为了公开。改变你的方法,这样你就不需要它了。

当然,可能您确实想引用不同的类型...您是否正在阅读 此页面有可能吗?我的猜测是,SecurityUtils 是一个不同的自定义类,而不是 System.Web.SecurityUtils

它所做的只是为网站设置一个默认过期时间——无论如何,这可能是您想要以自己的方式实现的。它可能只是一个常量,或者可能是设置文件中的某些内容。那里不会有很多逻辑。

You can't - as it says, System.Web.SecurityUtils is inaccessible. You can't make it public - it's not designed to be public. Change your approach so that you don't need it.

Of course, it could be that you really want to refer to a different type... were you reading this page by any chance? My guess is that here, SecurityUtils is a different custom class, not System.Web.SecurityUtils.

All it's doing is getting a default expiry for the site though - and that's probably something you want to implement in your own way anyway. It's likely to just be a constant, or possibly something from a settings file. It's not like there's going to be a lot of logic there.

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