Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Christian Liebe-Harkort 56 posts 104 karma points
    Feb 13, 2010 @ 13:01
    Christian Liebe-Harkort
    0

    Integrating ASPNET Membership

    Hi there,

    I am in the progress of moving a running site to umbraco and so far I have to say that almost everything is working fine and I love the new features that I have within umbraco.

    The last major thing I have to do is integrating ASPnet Membership control with Umbraco, because my site has existing users (=umbraco members) I want to use. When I created that site I merged the aspnet.db to my site using aspnet_regsql tool and created some relations between these tables and my custom tables, so want to leave this at it is.


    I read the HowTo http://our.umbraco.org/wiki/how-tos/membership-providers/how-to-integrate-aspnet-membership-control-with-umbraco

    but I can't get this running and probably don't understand some details.

    The relavant sections in my actual and running non-umbraco web.config look like:

    <connectionStrings>
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer"
    connectionString="Data Source=SQL_SERVER_ADDRESS\SQLINSTANCE;Initial
    Catalog=DATABASE_NAME;User ID=SOME_SQL_USERNAME;Password=somepassword"
    providerName="System.Data.SqlClient"/>
    <add name="APPLICATION_ConnectionString" connectionString="Data Source=SQL_SERVER_ADDRESS\SQLINSTANCE;Initial Catalog=DATABASE_NAME;User ID=SQL_USERNAME;Password=secret" providerName="System.Data.SqlClient"/>
    </connectionStrings>

    <membership>
    <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider"
    connectionStringName="LocalSqlServer"
    applicationName="MY_Application"
    maxInvalidPasswordAttempts="5"
    minRequiredPasswordLength="8"
    enablePasswordReset="true"
    requiresQuestionAndAnswer="true"
    minRequiredNonalphanumericCharacters="1"
    type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </providers>
    </membership>

    <profile>
    <providers>
    <remove name="AspNetSqlProfileProvider"/>
    <add name="AspNetSqlProfileProvider"
    connectionStringName="LocalSqlServer"
    type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </providers>
    </profile>

    <roleManager enabled="true">
    <providers>
    <remove name="AspNetSqlRoleProvider"/>
    <remove name="AspNetWindowsTokenRoleProvider"/>
    <add name="AspNetSqlRoleProvider"
    connectionStringName="LocalSqlServer"
    applicationName="MY_Application"
    type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    <add name="AspNetWindowsTokenRoleProvider"
    applicationName="checkerplay"
    type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </providers>
    </roleManager>

    In the HowTo, the provider section looks like:

    <providers>
    <clear />
    <add name="SqlProfile" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="umbracoDb" applicationName="DemoUmbraco4" />
    </providers>

    I tried to take the sections provided in the HowTo and replaced the applicationName="DemoUmbraco4" and the connection strings.
     
     Do I have to provide the connectionString "umbracodb", or is that provided by default (I could not find the place where the umbraco db-connection is configured)?
     
     What should the umbraco web.config look like?
     
    Cheers
    Christian 

  • Stephan Lonntorp 195 posts 212 karma points
    Feb 13, 2010 @ 15:16
    Stephan Lonntorp
    0

    Umbraco currently uses an appSettings value for its db connection, but you could add the same connectionstring to the connectionStrings section.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Feb 14, 2010 @ 07:34
    Aaron Powell
    1

    The Umbraco connection string and the SQL Membership connection string are entirely unrelated. Sure the tables can be in the same database, resulting in the same connection string but that is more of a side-effect.

    Are you actually receiving an error, that would be really useful for giving you a solution.

    Since Umbraco 4 we have supported the ASP.NET Membership Provider model, so the web.config will look the same if you're wanting to use the built-in members or one of the framework options. Ensure that you set the defaultProvider of the <membership /> node (this should be the name attribute of your custom provider), there is also a similar option in the /config/umbracoSettings.config file.

  • Christian Liebe-Harkort 56 posts 104 karma points
    Feb 14, 2010 @ 13:07
    Christian Liebe-Harkort
    5

    Hi,

    slace thanks for your useful hints. I finally got this to work and, because this was giving me kind of a hard time. I want to share my steps with the people, that experience the same problems. I think my main problem was, not to realize that web.config starts out with actually everything prepared to use ASPNET memebership providers.

    actually I started out using the boost (runaway) website.

    The first thing I did, was adding my connectionstring, so that I can use the data for my controls etc.
    ConnectionStrings.config looks like:

    <?xml version="1.0" encoding="utf-8" ?>
    <connectionStrings>
    <add name="MY_ConnectionString"
         connectionString="Data Source=SQLSERVER\SQLINSTANCE;Initial Catalog=MY_database;User ID=some_database_user;Password=secret"
         providerName="System.Data.SqlClient"/>
    </connectionStrings>

    Next Step:

    I added the connection string that I want to use for the Member and Role Provider:

    <add name="MY_MEMBER_AND_ROLE_ConnectionString" 
         connectionString="Data Source=SQLSERVER\SQLINSTANCE;Initial Catalog=MY_database;User ID=another_database_user;Password=secret"
         providerName="System.Data.SqlClient"/>

    I started out with these sections in my web.config (I guess this is default in Umbraco 4.0.2 boost):

        <!-- Membership Provider -->
        <membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
          <providers>
            <clear />
            <add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="TestType" />
            <add name="AspNetSqlMemberShipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LocalSqlServer" />
            <add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" />
          </providers>
        </membership>
        <!-- added by NH to support membership providers in access layer -->
        <roleManager enabled="true" defaultProvider="UmbracoRoleProvider">
          <providers>
            <clear />
            <add name="UmbracoRoleProvider" type="umbraco.providers.members.UmbracoRoleProvider" applicationName="umbraco" />
          </providers>
        </roleManager>
       

      
      I followed your advice to set the defaultProvider to AspNetSqlMemberShipProvider and there set the connectionstring to MY_MEMBER_AND_ROLE_ConnectionString and adding an applicationName.
     
      So now I was able to see my users in the Members Section in the umbraco backend.
     
    Partial  success!
     
      Strangly creating a user produces YSOD:

      [ProviderException: No user with name 'test' exists]
         umbraco.providers.members.UmbracoRoleProvider.IsUserInRole(String username, String roleName) +102
         System.Web.Security.Roles.IsUserInRole(String username, String roleName) +398
         umbraco.cms.presentation.members.EditMember.Page_Load(Object sender, EventArgs e) +1351
         System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
         System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
         System.Web.UI.Control.OnLoad(EventArgs e) +99
         umbraco.BasePages.BasePage.OnLoad(EventArgs e) +15
         System.Web.UI.Control.LoadRecursive() +50
         System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

    But the user is still created and looks ok. I can search/browse/ delete the users.

    The message gives me the hint, that there is something wrong with the membership provider, so next step:

    I added the Settings form my other web.config:

    <add name="AspNetSqlRoleProvider"
                 connectionStringName="LocalSqlServer"
                 applicationName="MY_application"
                 type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

    and set the connectionStringName to MY_MEMBER_AND_ROLE_ConnectionString and also the   roleManager defaultProvider to "AspNetSqlRoleProvider".

    Cool: Now everything is looks good and is working!

    @Stephan:

    Ok I have these settings in   <appSettings>:
        <add key="umbracoDbDSN" value="server=SQLSERVER\SQLINSTANCE;database=umbraco;user id=umbracousr;password=somepw" />

    Still don't really see where and how this is used and connected, but obviously it is used and works!.


    Thanks.

    Christian

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Feb 14, 2010 @ 22:55
    Aaron Powell
    0

    The Umbraco built-in provider uses the Umbraco database, which is why it would use the Umbraco connection string, not any custom one you define.

    Using the AspNetSqlMembership will use what ever connection string you tell it (provided it's in the <connectionStrings /> config section)

Please Sign in or register to post replies

Write your reply to:

Draft