Custom Apps within Community Server
A few months ago, a client of mine asked for the ability to host a custom app from within their Community Server deployment. Well, I got to working with TheMan and we built a web.config that basically restored the settings in a virtual directory within a CS deployment to the defaults for ASP.Net.
So - first, here's the requisite HelloWorld program.
How'd we do it - basically, we're going to reset, remove, clear, add:
- Remove alll of the added assemblies by name.
- Reset the page base type (if you're running ASP.Net 2.0)
- Reset your custom errors
- Remove httpModules
- Remove httpHandlers
- Reset your Authentication
- Clear membership, role and profile providers and add your defaults from your machine.config
That's it - good luck!
You want more detail? Ok - this article was written for a CS2.1.60809.935 running on ASP.Net 2.0.
In my web.config (which should be the one that comes with the CS2.1 download - a copy is available here), starting at the top, we find:
<compilation defaultLanguage="c#" debug="false">
<assemblies>
<add assembly="MemberRole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7c773fb104e7562"/>
</assemblies>
</compilation>
My helloworld app isn't going to use MemberRole, so let's kill it. Take the web.config for your custom app and put in:
<compilation defaultLanguage="c#" debug="true">
<assemblies>
<remove assembly="MemberRole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7c773fb104e7562"/>
</assemblies>
</compilation>
I use copy/paste. If you're an old unix geek you can s/add/remove and you're set.
Continuing on... we find:
<pages validateRequest="false" enableEventValidation="false" autoEventWireup="true" pageBaseType="CommunityServer.Components.CSPage, CommunityServer.Components"/>
My helloworld app isn't going to use CommunityServer.Components.CSPage, etc, so let's kill it... But what is the default pageBaseType? Well - the Page class belongs to "System.Web.UI" so you can set this to System.Web.UI.Page.
Moving on... Next I run into <httpModules> and <httpHandlers>. Here, you just need to "remove" all of the custom settings:
<httpModules>
<remove name="CommunityServer" />
<remove name="CSProfile" />
<remove name="CSRoleManager" />
</httpModules>
<httpHandlers>
<remove verb="GET" path="Utility/redirect.aspx" />
<remove verb="GET" path="aggbug.aspx" />
<remove verb="GET" path="avatar.aspx" />
<remove verb="GET" path="vcard.aspx" />
<remove verb="GET" path="r.ashx" />
</httpHandlers>
Now we get into the custom providers that CS uses. Luckily, there's a lovely <clear /> statement that we can use to blow away all of the providers. This is a problem, though, because ASP.Net loads some default providers. We need to add them back but I don't know off the top of my head what they are. When in doubt, look at your microsoft.net/framework/CONFIG directory for the default setting. Doing so, I find default membership, profile and roleManager providers in my machine.config and add the following lines to the end of my custom app's web.config and we're done!
- <membership defaultProvider="AspNetSqlMembershipProvider">
- <providers>
- <clear />
- <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
- </providers>
- </membership>
- <profile defaultProvider="AspNetSqlProfileProvider">
- <providers>
- <clear />
- <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
- </providers>
- </profile>
- <roleManager defaultProvider="AspNetSqlRoleProvider">
- <providers>
- <clear />
- <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
- </providers>
- </roleManager>
Ok - here is the final web.config for my custom app.