如何更改为公开
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能 - 正如它所说,
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, notSystem.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.