Use the membership class to determine whether a user exists
------------------------- Proficient in ASP. net2.0 enterprise-level project development and learning notes
Some time ago I bought the enterprise-level project development proficient in ASP. net2.0 published by the People's post and telecommunications Publishing House. For me who lack the enterprise-level project experience, I may be attracted by the enterprise-level projects. After a period of study, I found that this book has some advantages for beginners like ours, but there are also many errors. Here, I will record the problems I found in my study, I hope to help new users at the same level as me and also a summary of their own learning.
In the OA system development of this book Code
Public Bool Sendmsg ( String Receive, String Send, String Title, String Content)
{
// First, you must determine whether the entered user name is correct.
If (Membership. findusersbyname (receive) = Null )
Return False ;
Else
This is a piece of code in the message sending method, which is intended to use membership. finduserbyname () determines whether the input user exists. If so, the sending operation is just executed. If not, a false value is returned. However, during the unit test, I found that the operation of sending information is performed no matter whether the user exists or not, and a sending record is added for querying database table files. By checking msdn, we found that the finduserbyname method returned a set of membershipusercollection. Through tracking, we found that even if the user does not exist, it is impossible to return a null value. another membership method getuser () in msdn caught my attention. setProgramThe changes are as follows:
Public Bool Sendmsg ( String Receive, String Send, String Title, String Content)
{< br> // first, you must determine whether the user name is correct.
If (membership. getuser (receive) = null )
return false ;
else
run the test, and the program runs as expected