Running BlogEngine.NET 2.5 using SQL Server 2005/2008

Topics: ASP.NET 2.0, Business Logic Layer
Dec 5, 2011 at 12:26 AM
Edited Dec 5, 2011 at 4:35 AM

Hi,

I had BlogEngine 2.5 as a Web Application running perfectly well within my existing MVC 3 ASP.NET 4 Web Application until I attempted to get BlogEngine to use the existing ASP Membership tables within in my SQL Server.  I have done everything (including running the MSSQLSetup2.5.0.0.sql file against my sql server 2008 database) as instructed within the ReadMe file entitled "Running BlogEngine.NET 2.5 using SQL Server 2005/2008:" which is within the BlogEngine.Net 2.5 setup folder.

However on my localhost  ASP.Net Development server, when I attempt to run the Web Site Administration Tool and click on the Security tab I receive the following error about the xmlMembershipProvider object on line 103 not being referenced:

 

There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store. 

The following message may help in diagnosing the problem: Object reference not set to an instance of an object. (C:\Users\teach\Documents\Visual Studio 2010\Projects\BlogEngine.Net\BlogEngine.Net\web.config line 103)

 

Any help/guidance will be much appreciated.  Thanks in advance.

Coordinator
Dec 5, 2011 at 10:53 AM

What does your web.config file look like?

In the SQLServerWeb.Config file included in the setup folder, it's setup to use the "DbMembershipProvider" and "DbRoleProvider" which are BE specific providers that do not use the standard ASP.NET membership tables (aspnet_xxxx).

The standard Role and Membership providers are included in that sample SQLServerWeb.Config file.  They are named "SqlRoleProvider" and "SqlMembershipProvider".  So your defaultProvider for <membership> and <roleManager> should be SqlRoleProvider and SqlMembershipProvider.  It should look like this:

<membership defaultProvider="SqlMembershipProvider">
	<providers>
		<clear/>
		<add name="XmlMembershipProvider" type="BlogEngine.Core.Providers.XmlMembershipProvider, BlogEngine.Core" description="XML membership provider" passwordFormat="Hashed"/>
		<add name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="BlogEngine" applicationName="BlogEngine"/>
		<add name="DbMembershipProvider" type="BlogEngine.Core.Providers.DbMembershipProvider, BlogEngine.Core" passwordFormat="Hashed" connectionStringName="BlogEngine"/>
	</providers>
</membership>
<roleManager defaultProvider="SqlRoleProvider" enabled="true" cacheRolesInCookie="false">
	<providers>
		<clear/>
		<add name="XmlRoleProvider" type="BlogEngine.Core.Providers.XmlRoleProvider, BlogEngine.Core" description="XML role provider"/>
		<add name="SqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="BlogEngine" applicationName="BlogEngine"/>
		<add name="DbRoleProvider" type="BlogEngine.Core.Providers.DbRoleProvider, BlogEngine.Core" connectionStringName="BlogEngine"/>
	</providers>
</roleManager>

And then make sure the "BlogEngine" connection string in the web.config file is set correctly.

Dec 5, 2011 at 3:04 PM

Hi BenAmanda,

 

Thank you for kindly responding so quickly.  I have indeed done everything that you said including setting the appropriate sql provider, however, I still received that same error message.  

So what I have had to do for now so that I can use the sql membership and role providers is to simply comment out the  following lines:

<add name="XmlMembershipProvider" type="BlogEngine.Core.Providers.XmlMembershipProvider, BlogEngine.Core" description="XML membership provider" passwordFormat="Hashed"/>
<add name="XmlRoleProvider" type="BlogEngine.Core.Providers.XmlRoleProvider, BlogEngine.Core" description="XML role provider"/>

As a result the aforementioned error is no longer displayed when I run the Website Admin Tool and click on the Security tab.  However, I then realised that the Website Admin Tool and the Users section of the BlogEngine.Net admin area was showing that I had 0 members/users in my existing ASP Membership tables which I know is not true.   So after scouring the web I learned that I had to share the applicationname  in the BlogEngine.Net web.config file with the applicationname in my existing MVC 3 Web Application's web.config file and ensure that the Application ID is the same for each user in the Membership tables and  linked to the same applicationname.  After doing that I can now use the ASP.Net Website Admin Tool and BlogEngine.Net admin area to view and mange all of the roles and users that were created by my existing MVC 3 Web Application.  I can seperately log in to BlogEngine.Net using those members/users credentials.

The problem that I am having now is that if I log into my existing MVC 3 Web Application, BlogEngine still prompts me to log in again when I try to access the admin area.   I need to be able to log in to my existing MVC web application and then for BlogEngine.Net to somehow recognise that I am already logged in using one of the users/members in the ASP Membership tables that my two web application share.

For what it's worth I am using the standard authentication code in my existing MVC 3 Web Application:

 if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

....

Any help or guidance would be much appreciated.

 

 

Coordinator
Dec 5, 2011 at 3:46 PM

You also need to share cookie name for both apps, something like:

<forms name=".AUXBLOGENGINE" ... >
<roleManager cookieName=".BLOGENGINEROLES" ...>