AsiMembershipPriovider

I am trying to get my Sharepoint based application to use the AsiMembershipProvider as its custom provider. It does not seem to work. To simplify things, I created a basic web application in VS 2008 and again tried to use the AsiMembershipProvider but it still doesn’t work.

 
Here are the steps I have taken:
- I copied the Asi.Providers.dll into the bin of my web app
- I add the connection string and membership configuration directly from the IMIS application web.config. Here is the membership config I am using:
<membershipdefaultProvider="AsiMembershipProvider">
      <providers>
              <addname="AsiMembershipProvider"type="Asi.Providers.AsiMembershipProvider, Asi.Providers"provider="CustomizedProvider"/>              <addname="CustomizedProvider"type="System.Web.Security.SqlMembershipProvider"connectionStringName="DataSource.iMIS.Connection"applicationName="iMIS"requiresQuestionAndAnswer="false"minRequiredPasswordLength="6"minRequiredNonalphanumericCharacters="0"requiresUniqueEmail="false"maxInvalidPasswordAttempts="5"/>
        </providers>
    </membership>
 
However, when the page loads, the .NET framework tries to instantiate an instance of the provider and I get and error:
 Exception has been thrown by the target of an invocation. (C:\Inetpub\wwwroot\wss\VirtualDirectories\7949\web.config line 83)”
Where line 83 =
<addname="AsiMembershipProvider"type="Asi.Providers.AsiMembershipProvider, Asi.Providers"provider="CustomizedProvider"/>
 
I assumed the constructor of the provider is referencing something that it can’t find so I copied all of the files from the IMIS15 web bin folder to my web app but it did not solve the problem.

Has anyone ever used the AsiMembershipProvider for a custom app? Any information on this would be greatly appreciated!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Add the following to the

Add the following to the Application Start event in global.asax:

iboAdmin.InitializeSystem();

That was magic!

I really appreciate your hint there. Like magic, now my mock up "login" test page loads fine. However, I am running into the userProviderKey: "providerUserKey was not a valid format for a GUID."

I have tried using a generic asp.net create user wizard on the page and also a just using your code from the http://www.imiscommunity.com/creating_imis_logins article you posted. Both fall to the same fate (Error found in the event viewer). My guess is that both methods are sending a null to the userProviderKey argument. I am coming to the conclusion that one cannot create a new membership user in IMIS unless there is already a contact record and you know the contact ID. This realization is also based on my understanding of your comment from the above article (I am using 15.1):"Note that in iMIS 15.1.0 and higher, the providerUserKey should be the ContactKey of the user's row in ContactMain".

I have also seen that the "CreateImisUser" web method in the MembershipWebService requires you to enter a valid contact Id for it to work. If I am right about all of this, I guess I need an addContact service that returns a userProviderKey that I can use to create credentials before I can create an imis user by any method. Does this sound right?

 

Yes, you will need to create

Yes, you will need to create the contact (the easiest way is probably to use iBO.NET; note that if you do it this way, you can use iBO.NET to create the logins as well, if you prefer) before creating the user.

AppPrincipal issue when trying to create the user with contactID

Thanks - I have been trying to create the new user with the  iBO CContact class. I try to create a contact record first, and then trying to use that contact ID to populate the "providerUserKey" argument of the CreateUser method. This almost works... the Contact.Save() method does change the contact objects contactId from "GuestUser" to an numeric value that is the incremented value of the next contactID in the IMIS database.However, when I call the CreateUser method, I get a strange error:

System.Runtime.Serialization.SerializationException: Type is not resolved for member 'Asi.Security.AppPrincipal,Asi, Version=15.1.1.2998, Culture=neutral, PublicKeyToken=null'.
 

My assembly does reference Asi.dll so it is not clear to me why it wouldn't be able to find it. My guess is that perhaps the error message is misleading. Do I have something configured wrongly?

Here is my code:

protected void Button1_Click(object sender, EventArgs e)

        {

// create a temporary user

            IiMISUser user = CStaffUser.LoginByUserId(ConfigurationSettings.AppSettings["System.WebLogin"]);

        

             // create a new contact record

            CContact contact = new CContact(user);

  

            // use following method to generate a numberic contactID, replacing "guestID".

            //This works, but I can't see the new contact any where in IMIS

           contact.Save();

 

            // now try to make the user with the new contact ID for the providerUserKey

           string username = "emeans1";

           string password = "password";

           string email = "emeans@advsol.com";

           string passwordQuestion = "What is your favorite color?";

           string passwordAnswer = "Blue";

           object providerUserKey = contact.ContactId;

           System.Web.Security.MembershipCreateStatus status;

 

 // this call crashes with above exception

           System.Web.Security.MembershipUser newUser =

           System.Web.Security.Membership.CreateUser

           (username, password, email, passwordQuestion, passwordAnswer, true, providerUserKey, out status);

     

        }

 

I'm not sure what the error

I'm not sure what the error means, but you need to pass the ContactKey for the contact, which is not the same as the ContactId.

Unfortunately, iBO.NET doesn't know anything about ContactKey, so the easiest way to do this is to use BOD objects:

using Asi.Business;

object providerUserKey;
using (Asi.Security.SecurityContext.ImpersonateAnonymous())
{
    BusinessContainer container = new BusinessContainer("ContactContainer");
    BusinessController contactController = BusinessController.NewBusinessController(container, "NetContact");
    BusinessItem netContact = contactController.SelectWithFilter(true, new BusinessFilter("ID", Asi.ComparisonType.Equal, contact.ContactId))[0] as BusinessItem;
    providerUserKey = netContact.GetGuid("ContactKey");
}

Also, make sure you reference both Asi.dll and Asi.Lexicon.dll; the latter is a required DLL as well.

Cant save contact, Null Ref exception

Thanks for the heads up. However, my current problem is that I have discovered that the contact object isn't actually getting saved. It was adding validation error object to "Errors" letting me know I needed to add the first name. So I changed my code to the following:

  IiMISUser user = CStaffUser.LoginByUserId(ConfigurationSettings.AppSettings["System.WebLogin"]);

 // create a new contact record

 CContact contact = new CContact(user);

 

contact.FirstName = "Elvis";

//After this, the following throws a Null reference exception...

contact.Save();

I ran a trace on my iMIS database and it appears that the last thing sql call is an INSERT into the address info in "name-adress". However, I quick check reveals that no records were created in that table. Apparently, that table is rejecting the INSERT statement and the code is crashing. Have you seen this before? Could the DB be configured incorrectly?

SQL Statement works when copied and pasted into query

I wanted to mention that I copied and pasted the INSERT statement form the trace to a query and it worked on its own (i.e. it inserted a record into the name_address table). I am guessing now that maybe the error occurs in the code after the address is written and then it causes the new records to be rolled back

Can you post the full error

Can you post the full error information including stack trace?

SQL Problem Fixed, back to serialization issue

Hi there - thanks for your continued attention. Today I reinstalled my dev version of the imis database and the null reference error went away - not I can write contacts with the code I posted above (yeah)! However, I still can't write members (boo) due to the orginal serialization issue i posted yesterday (see above). I have been researching the error and it seems as though it is due to the fact that I am using the Visual Studio development server to debug my project. Apparently, that server has issues with serializing custom Prinicipals (http://www.lhotka.net/weblog/CommentView,guid,cfcaf6c4-63cf-4cf1-8361-ed3db07496a4.aspx). Apparently, the easiest way to work around this is to have the class (in this case, the Asi,Security.AppPrincipal class) inherit MarshalByRefObject at the base. Of course, I can't do this.

I will try to use IIS to debug tomorrow. My efforts to do this today caused me to run into all kinds of SQLClientPermission errors on the iboAdmin.InitializeSystem() call.

That's interesting regarding

That's interesting regarding Cassini... we all use IIS to develop internally, or I'm sure we'd have seen this before. Thanks!

Valid credentials must be provided by the application principal.

Please help out i kept getting this problem.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Asi.Data.DataServerCredentialsException: Valid credentials must be provided by the application principal.

Source Error:

Line 21: 
Line 22:             // Code that runs on application startup    
Line 23:             iboAdmin.InitializeSystem(
Line 24:                 "Data Source=SEVSQ10-VM\\ECACORE2005;User ID=sa;Password=tweed_heads;Initial Catalog=IMIS15");
Line 25: 

Source File: D:\EcaDevelopment\EcaApplicationsNet2\Projects\CRM\Mainline\src\Source\IBOTest\Global.asax.cs    Line: 23

Stack Trace:

[DataServerCredentialsException: Valid credentials must be provided by the application principal.]
   Asi.Data.DataServer..ctor(AppPrincipal appPrincipal) +173
   Asi.Primitive.LicensePrimitive.VerifyLegacyLicenseChecksum() +2291
   Asi.iBO.iboAdmin.ValidateChecksum() in E:\TFS\devBranches\Coleto\imis.net\Packages\iBO\Asi.iBO\iboAdmin.cs:821
   Asi.iBO.iboAdmin.LoadLicense() in E:\TFS\devBranches\Coleto\imis.net\Packages\iBO\Asi.iBO\iboAdmin.cs:834
   Asi.iBO.iboAdmin.InitializeSystem(String connectionString) in E:\TFS\devBranches\Coleto\imis.net\Packages\iBO\Asi.iBO\iboAdmin.cs:691
   IBOTest.Global.Application_Start(Object sender, EventArgs e) in D:\EcaDevelopment\EcaApplicationsNet2\Projects\CRM\Mainline\src\Source\IBOTest\Global.asax.cs:23

Server Error in '/' Application.

Valid credentials must be provided by the application principal.

 


Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082

 

Check your bin folder

I've seen this error and I think the message can be misleading. Typically for me it means I have not put the correct dlls in the bin folder of the executing application. An typically, the one I forget is log4net. You should start by ensuring you have Asi.dll and log4net.dll in the bin folder.

And Asi.Lexicon.

And Asi.Lexicon.

I have both assemblies in

I have both assemblies in the bin folder

Log4net settings need to be

Log4net settings need to be included in the config file, solution!

Forgot about that....

So is the problem solved?