Developer forum

Forum » Development » Dynamiweb.Security in custom module

Dynamiweb.Security in custom module

Magnus Holmberg
Reply
Hi

We have created a custom module that fetches customer information from a system then creates the user and then when we are going to login the user using
 Dynamicweb.Security security = new Dynamicweb.Security();
                    security.ExtranetLogin(user.UserName, user.Password);

We gets this error "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."

I got the same error in 19.2.1.? when creating the user, now I get this error login in the user in 19.2.4.1.

Is this a bug or am I doing something wrong?

Kind regards
//Magnus


Replies

 
I. Sergey
Reply
Hi Magnus,

I just tried this:

Dynamicweb.Backend.User user = new Dynamicweb.Backend.User();
user.UserName = "test";
user.Password = "test";
Dynamicweb.Security security = new Dynamicweb.Security();
security.ExtranetLogin(user.UserName, user.Password);

And it works fine.
Can I see how you create your user?

 
Nicolai Høeg Pedersen
Reply
Hi Magnus.

I think it is because that method does a redirect because your login fails. Try "Try catch" your ExtranetLogin call to catch the thread aborted exception:
http://support.microsoft.com/kb/312629/EN-US/


 
Magnus Holmberg
Reply
Hi guys!

I tested to created the user as Sergey said and then it works just fine, but I am creating the user with Usermanagement like this:
var group = Dynamicweb.Modules.UserManagement.Group.GetGroupByID(groupID);
var newUser = new Dynamicweb.Modules.UserManagement.User(groupID);
newUser.UserName = Guid.NewGuid().ToString().Replace("-""").Remove(8);
newUser.Password = Guid.NewGuid().ToString().Replace("-""").Remove(8);
newUser.Name = group.Name;
foreach (var item in newUser.CustomFieldValues)
{
switch(item.CustomField.SystemName)
{
    case "AccessUser_Skapad":
    item.Value = DateTime.Now;
    item.CustomField.Save();
    break;
    }
}
newUser.Save();
I also tried to create a user in Admin - Usermanagement and then just login with Security and it fails the same way.
Used try catch(ThreadAbortException ) but it types the same error
"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."
It worked before I upgraded to the "new" usermanagement and as I said I got same sort of error when trying create a user with version 19.2.1.? But now it woks creating a user in 19.2.4.1
Could it be that I miss some module?

Yes as you say it redirects to a Page but with error in the Url... it adds the Language in front like this /sv-SE/default.aspx?ID=48

Kind regards.
//Magnus

 
I. Sergey
Reply
I created new Custom field "Skapad" and tried this:

var group = Dynamicweb.Modules.UserManagement.Group.GetGroupByID(255);
            var newUser = new Dynamicweb.Modules.UserManagement.User(255);
            newUser.UserName = System.Guid.NewGuid().ToString().Replace("-", "").Remove(8);
            newUser.Password = System.Guid.NewGuid().ToString().Replace("-", "").Remove(8);
            newUser.Name = group.Name;
            foreach (var item in newUser.CustomFieldValues)
            {
                switch (item.CustomField.SystemName)
                {
                    case "AccessUser_Skapad":
                        item.Value = System.DateTime.Now;
                        item.CustomField.Save();
                        break;
                }
            }
            newUser.Save();

            Dynamicweb.Security security = new Dynamicweb.Security();
            security.ExtranetLogin(newUser.UserName, newUser.Password);

And it works just fine.
Maybe something wrong with your group where you try to create new user. And what type of your Custom field do you have?
 
Magnus Holmberg
Reply
This post has been marked as an answer
It was something wrong with the group so I deleted it and created a new and then it worked.

Thanks alot for the help and support.
Keep up the good work

//Magnus

Votes for this answer: 0

 

You must be logged in to post in the forum