Hosting ASP.Net Mvc in SharePoint

  • Enabling Asp.Net 3.5 in SharePoint 2007 Sites
  • Start Visual Studio 2008.
  • Create a new dummy ASP.NET Web Application Project, and make sure you target the .NET Framework 2.0 (upper right dropdown of the New Project dialog). The name of this project is not important; you won’t need it anymore when we’re done.
  • Copy the web.config of your SharePoint 2007 site, into the dummy Web Application project in Visual Studio.
  • Open the Project Properties in Visual Studio (right click on the Project node in the Solution Explorer, and choose Properties; or in the Project menu, select WebApplicationX Properties).
  • Select .NET Framework 3.5 in the Target Framework dropdown (select Yes in the confirmation dialog).
  • Copy the web.config from the Web Application Project back to SharePoint.
  • If you want to use <ScriptManager> in SharePoint MasterPage,you need to modify web.config <SafeControls>.
<SafeControls>
    <SafeControl Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TypeName="*" Safe="True" />
</SafeControls>
  • Register Routes and ASP.Net Mvc
  • Modify the web.config like bellow:
<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </httpHandlers>
    <httpModules>
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add name="SPMvcModule" type="SimOne.SharePoint.ApplicationRuntime.SPMvcModule, SimOne.SharePoint.Solutions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f4c6cf0632dabc3c"/>
    </httpModules>
    <compilation batch="false" debug="false">
      <assemblies>
        <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </assemblies>
    </compilation>
    <pages enableSessionState="false" enableViewState="true" enableViewStateMac="true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7">
      <namespaces>
        <add namespace="System.Web.Mvc"/>
        <add namespace="System.Web.Mvc.Ajax"/>
        <add namespace="System.Web.Mvc.Html"/>
        <add namespace="System.Web.Routing"/>
        <add namespace="System.Linq"/>
        <add namespace="System.Collections.Generic"/>
      </namespaces>
    </pages>
    <trust level="Full" originUrl=""/>
  </system.web>
  <system.webServer>
    <handlers>
      <remove name="MvcHttpHandler"/>
      <remove name="UrlRoutingHandler"/>
      <add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </handlers>
  </system.webServer>
</configuration>

Last edited Dec 29, 2009 at 1:10 PM by WindBell, version 1

Comments

No comments yet.