MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

Integrate MonoX with existing application and user store  (Mono Support )

Viewed 3909 time(s), 12 post(s) 11 month(s) agoby sgoldgeier
sgoldgeier

sgoldgeier

11 month(s) ago
I have successfully downloaded and installed the MonoX application. I currently have an existing application that I wish to integrate with MonoX. My current application has a user store (not using ASP.NET Membership). I want the user to automatically get logged in to the MonoX site if they are already logged in to my main site. Is this possible without the source code? Also, if I were to get the source code, would this be something that could be done fairly easily, or would it require a lot of customization?

Thank you for your help.
Sam
This content has not been rated yet. 
45 Reputation 7 Total posts
khorvat

khorvat

11 month(s) ago
Hi,

Is your application running on ASP.NET and which version are you using ? Is single-sing-on something that will help you to automatically login users ? If so you can check the following post.

Regards
This content has not been rated yet. 
15993 Reputation 2214 Total posts
sgoldgeier

sgoldgeier

11 month(s) ago
Thanks for the response. My application is running ASP.NET Web Forms. Unfortunately, I am not able to get single sign on working.

For testing, I created a simple second web application that has the same <forms> and <machinekey> elements in the web.config as the MonoX web.config. For the machineKey, I added and modified the validationKey and decryptionKey so that they match in both web.config files. Therefore, they should share the same ticket.

I created a simple login page on my main site that logs in the user "mary", creating the forms authentication ticket:
FormsAuthentication.SetAuthCookie("mary", false);
  
FormsAuthenticationTicket ticket1 =
   new FormsAuthenticationTicket(
        1,                         // version
        "mary",   // get username  from the form
        DateTime.Now,                        // issue time is now
        DateTime.Now.AddMinutes(10),         // expires in 10 minutes
        false,      // cookie is not persistent
        ""                              // role assignment is stored
                                          // in userData
        );
HttpCookie cookie1 = new HttpCookie(
  FormsAuthentication.FormsCookieName,
  FormsAuthentication.Encrypt(ticket1));
Response.Cookies.Add(cookie1);
  
Response.Redirect("Default.aspx");

However, when I go back to the MonoX site, the User.Identity.Name is blank, instead of being "mary".

Please tell me if there's something I'm doing incorrectly.
This content has not been rated yet. 
45 Reputation 7 Total posts
sgoldgeier

sgoldgeier

11 month(s) ago
It looks like the forms authentication ticket was not able to be read. The issue was with the <httpRuntime> element. My target framework was set to 4.5. If I set it to 4.0, then the forms authentication ticket could then be read and User.Identity.Name is displayed.

I changed the web.config element as follows:
<httpRuntime targetFramework="4.0">
This content has not been rated yet. 
45 Reputation 7 Total posts
khorvat

khorvat

11 month(s) ago
Hi,

yes you need to sync frameworks and machineKey in web.config if you want to share the tickets. Did you manage to implement SSO and it's working or ?

Regards
This content has not been rated yet. 
15993 Reputation 2214 Total posts
sgoldgeier

sgoldgeier

11 month(s) ago
It seems to be working if the user already exists in the MonoX database.

However, what should I do if the user doesn't already exist in the MonoX database, but only exists in my main User database? Do I need to create an in between page that checks if the user exists in the MonoX database and if it doesn't, automatically insert a new record for them in MonoX? Are there any built in ways of doing this?
This content has not been rated yet. 
45 Reputation 7 Total posts
zhuber

zhuber

11 month(s) ago
Hi,

there are two options that can help you achieve desired implementation:
1. Create endpoint on your site which would sync users from both sites. That way you can send requests to that endpoint from MonoX site and receive required response data.
2. Override default authentication implementation where cookie is checked, extract username/email (all required fields for registering user on MonoX) from existing cookie, manually create user in MonoX based on extracted data and then login that user immediately after registration. Of course if that user is already present in MonoX database, registration part would not occur.

Regards,
Zeljko
This content has not been rated yet. 
145 Reputation 18 Total posts
sgoldgeier

sgoldgeier

11 month(s) ago
When you mention manually creating a user in MonoX based on extracted data, are you referring to manually creating the record directly in the MonoX database. Would this mean I should create a record in aspnet_Users and aspnet_Membership tables for new users? Are these the main, necessary tables I would need to add records to for new users? Is there anything else I would need to do?
This content has not been rated yet. 
45 Reputation 7 Total posts
zhuber

zhuber

11 month(s) ago
Hi,

you can use something like this:
if (!(Membership.Provider is System.Web.Security.SqlMembershipProvider))
{
    var success = DependencyInjectionFactory.Resolve<IUserBLL>().CreateUserManually(userNameToUse);
    if (success)
    {
       var authenticatedUser = Membership.GetUser(userNameToUse);
       authenticatedUser.Email = email;
       Membership.UpdateUser(authenticatedUser);
    }
}
else
{     
     // Use suitable CreateUser(..) overload based on available user data
    var authenticatedUser = Membership.CreateUser(userNameToUser, password, email);
}

Regards,
Zeljko
This content has not been rated yet. 
145 Reputation 18 Total posts
sgoldgeier

sgoldgeier

11 month(s) ago
If I add this code to a new page that I created, I don't have a reference to DependencyInjectionFactory.
This content has not been rated yet. 
45 Reputation 7 Total posts
1 2