API Questions on Kentico API.
Version 5.x > API > how to catch error when creating the user View modes: 
User avatar
Member
Member
wtzeng-micro-datanet - 7/29/2011 2:16:02 PM
   
how to catch error when creating the user
Hi
I have create a web service that able to create either single or multiple user in a single xml string.
If the ID already exist the sever will response error then the web service stop.

CMS.SiteProvider.UserInfoProvider.SetUserInfo() is returning void so I can't check if the SetUserInfo successful. I try to do Catch Exception, that won't work...

Is there a way I can check if SetUserInfo successful? because I want to the web service to skip the error, record in a log then continue to insert on the next user?

Thanks

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 7/30/2011 7:38:06 AM
   
RE:how to catch error when creating the user
Hi,

the method throws the exception:

throw new Exception("[UserInfoProvider.SetUserInfo]: Cannot insert new UserInfo record, user with username '" + user.UserName + "' already exists.");

Could you please share the code you are using for setting userInfo object?

Best regards,
Ivana Tomanickova


User avatar
Member
Member
wtzeng-micro-datanet - 8/1/2011 8:40:58 AM
   
RE:how to catch error when creating the user

try
{

CMS.SiteProvider.UserInfoProvider.SetUserInfo(NewUser);

}
catch (Exception ex)
{
throw ex;
//Record the error into a error log...//
}



User avatar
Member
Member
wtzeng-micro-datanet - 8/1/2011 8:55:23 AM
   
RE:how to catch error when creating the user
did I catch the wrong Exception? because the system does not catch if the user id already exist..

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/2/2011 7:58:17 AM
   
RE:how to catch error when creating the user
Hi,

I am sorry for confusion. The system really throws exception, but only in case that userName is not unique.

So the solution in this case is to try to find user in a database before he will be inserted, i.e. use following method from UserInfoProvider. If it returns empty dataset, user with mentioned id does not exist in the system:


public static DataSet GetUsers(
string where,
string orderBy
)

Best regards,
Ivana Tomanickova

User avatar
Member
Member
wtzeng-micro-datanet - 8/2/2011 8:20:54 AM
   
RE:how to catch error when creating the user
thanks