Monday, December 3, 2012

Adding an ASP.NET 4.0 application to a subdirectory on SharePoint 2010

My SharePoint 2010 site is running under SSL, and I have some web applications I want to keep as separate applications (aka, not publish them to SharePoint), and just have a web part page with a web page viewer.  This way, the page is harnessed within SharePoint, so it still has my SharePoint header\navigation, but its only showing a web application from https://intranet.myorg.com/MySubApplication

For setting this up, most of this was straightforward in that we had to create an "application" in IIS (7.5) underneath my SharePoint site, but I quickly hit a snag.  SharePoint 2010 runs under an ASP.NET 2.0 application pool.  Since 2.0 is old, I wrote my application in 4.0, so my parent (SharePoint) site is 2.0, but the child application is 4.0.

The issue here is that some settings\configurations are loaded because of the 2.0 framework, and launching the 4.0 framework application is also trying to inject similar settings, causing all hell to break loose (OK, just an error page.. but a sternly written one I must say).  To resolve, I did quite a bit of googling, and a little bit of loose translating from here:  http://translate.google.com/translate?sl=fr&tl=en&js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fsamsonfr.wordpress.com%2F2012%2F07%2F24%2Fintgrer-une-application-asp-net-mvc-3-sous-un-site-web-iis-hbergeant-sharepoint-server-2010%2F

In short, if you have to add a .NET 4.0 application as a sub-application to your SharePoint 2010 implementation, start with the usual steps, which are: 
  • Create a new application pool targeting the 4.0 Framework. 
    • If possible, give this the same identity to run under that your SharePoint site is running as. 
  • Then, create your directory on the server that will host your 4.0 application, and link to it within IIS (right-click the SharePoint web and click Add Application). 
  • Go ahead and deploy your application, and try to browse to it. 
If your in a similar spot than I, then you should have an error message similar to a 500.19, barking about a configuration error and that there is a duplicate <somethingOrOther> section defined.  To resolve...

  1. In your sharepoint web.config, we need to prevent inheritance of parent (sharepoint) settings, I surrounded system.web with:
    <location inheritInChildApplications="false" path=".">
    and
    </location>
  2. Also within our SharePoint config, I commented out the system.web.extensions section group (and everything within it), and added it to the .NET framework's 2.0 web.config, found at c:\windows\microsoft.net\framework64\v2.0.50727\config\web.config
  3. I then added the following to the modules section to my application's config file, to prevent these modules from inheriting
    <remove name="SPRequestModule"/>
    <remove name="PublishingHttpModule"/>
    <remove name="RSRedirectModule"/>
    <remove name="StateServiceModule"/>
    <remove name="SharePoint14Module"/>
At this point, I was still getting 500 error's, but the error message wouldn't even display for me.  Much like the aforementioned article, I had to enable Failed Request Tracking in IIS.  Once I did so, I found that the following error was occurring:
"Handler PageHandlerFactory-Integrated has a bad module ManagedPipelineHandler in its module list. 

Some more googling led me down the path that the 4.0 Framework wasn't installed properly.  That didn't make much sense to me, but it was easy enough to open a command line and execute: %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
Once I did so, my application started working.  Hope this helps!

No comments:

Post a Comment