neibribulmibe
New Member
I have an existing C# ASP.NET web application which uses the membership and role providers. The tables for these are hosted in the same DB which holds all of the application tables (hosted in Azure for production, local SQLExpress for dev).I would like to write a console application which uses the same user and role information. To this end I have enable client application services (on the console app) and added a new web service which exposes these to the console app.I can get this working in a test setup (both as console and winforms), i.e. with the web service creating its own blank set of users/roles which from what I've read are stored in a local file as a SQL CE database.How can I get the web service to be reading from my application's DB?Relevent web.config for original web application:\[code\]<profile defaultProvider="DefaultProfileProvider"> <providers> <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="SecondBiteDBContext" applicationName="/" /> </providers></profile><membership defaultProvider="DefaultMembershipProvider"> <providers> <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="SecondBiteDBContext" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="10" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> </providers></membership><roleManager defaultProvider="DefaultRoleProvider" enabled="true"> <providers> <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="SecondBiteDBContext" applicationName="/" /> </providers></roleManager>\[/code\]Web.config for the web service:\[code\] <system.web.extensions> <scripting> <webServices> <authenticationService enabled="true" requireSSL="false" /> <profileService enabled="true" readAccessProperties="WebSettingsTestText" writeAccessProperties="WebSettingsTestText" /> <roleService enabled="true"/> </webServices> </scripting> </system.web.extensions>....<system.web> <profile enabled="true" > <properties> <add name="WebSettingsTestText" type="string" readOnly="false" defaultValue="http://stackoverflow.com/questions/14500282/DefaultText" serializeAs="String" allowAnonymous="false" /> </properties> </profile></system.web>\[/code\]App.config for console app:\[code\]<?xml version="1.0" encoding="utf-8"?><configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <appSettings> <add key="ClientSettingsProvider.ServiceUri" value="http://localhost:31337/SecondBiteAppServices/Profile_JSON_AppService.axd" /> <add key="ClientSettingsProvider.ConnectionStringName" value="http://stackoverflow.com/questions/14500282/DefaultConnection" /> </appSettings> <connectionStrings> <add name="DefaultConnection" connectionString="Data Source=.\SQLExpress;Initial Catalog=SBAuto;MultipleActiveResultSets=True;Integrated Security=SSPI" /> </connectionStrings> <system.web> <membership defaultProvider="ClientAuthenticationMembershipProvider"> <providers> <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="http://localhost:31337/SecondBiteAppServices/Authentication_JSON_AppService.axd" connectionStringName="DefaultConnection" savePasswordHashLocally="False" /> </providers> </membership> <roleManager defaultProvider="ClientRoleProvider" enabled="true"> <providers> <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="http://localhost:31337/SecondBiteAppServices/Role_JSON_AppService.axd" cacheTimeout="86400" connectionStringName="DefaultConnection" /> </providers> </roleManager> </system.web></configuration>\[/code\]I haven't specified the optional credentials provider, because I'm not using a form - right now I can't get a hard coded call to validateuser() to succeed.Using project properties -> services tab -> advanced button, I've specified a custom connection string pointing to the required DB. I know it is connecting to my DB, because for a while I was getting exceptions about "invalid object ApplicationProperties". Creating a table in my DB with columns PropertyName and PropertyValue fixed this. Note that I had already run aspnet_regsql on my DB which I would expect should have created the required tables. However it is not passing validation checks on the users residing in that DB - it runs cleanly (no exceptions) but fails the login. Based on the structure of app.config above, I speculate that the custom connection string is only applying to the profile service, not the membership or role services? (Only the profile service [client settings provider] is taking the connection string as a param.) EDIT: Looking back at some docs, http://msdn.microsoft.com/en-us/library/bb384312 seems to indicate this custom connection string is only for storing the offline local cache stuff.Using project -> asp.net configuration (with the web service project selected), the web site admin tool doesn't let me do anything meaningful to configure the providers or add new ones.I haven't been able to track down anything that will let me actually use the users and roles in that DB. Any ideas? (I am fairly new to .net, so it is quite possible I'm missing something, but I've been having a lot of trouble with the documentation and getting any decent results out of google.)Once this is working, I want to share business logic between the various projects. Currently the logic is located in the main web app controller methods - obviously I will need to refactor that out to a shared layer. Will that be possible given the objects involved are based on entity framework? I did a trial refactor before I started with all of this client services stuff. I was able to get everything referenced and compiling but the code was failing silently very early in execution, my best guess was that all of the various framework related stuff was not initialized properly - hence entering into client app services. However I'm worried that even if I get CAS going, entity framework is going to still cause issues.Last one: how can I share config elements (connection strings mostly) between config files in different projects? Would like to be able to swap between dev and production without having to edit multiple files.EDIT: How much of a hack is doing something like this? http://devpinoy.org/blogs/comgen/archive/2007/08/15/use-membership-api-in-winforms.aspxThat's the only actually useful thing I've been able to find, even if not directly related to CAS. It seems like I could just copy the appropriate lines form my main web app web.config (which include a link to my DB's connection string).Thanks!