Reputation: 1725
I would like to use ASP.NET WebApi inside a SharePoint 2013 farm solution.
I know it is not supported out-of-the-box, but I found SignalR can be run by means of a simple HttpModule, so I was wondering whether a similar appoach could be used.
Thanks in advance, Rich
UPDATE June 2013
Made it working by reworking the HTTP Module shown in the mentioned post:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "kms2013/api/{controller}/{action}",
defaults: new { }
);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.Services.Replace(typeof(IAssembliesResolver), new SPAssemblyResolver());
HostingEnvironment.RegisterVirtualPathProvider(new WebAPIVirtualPathProvider());
SPAssemblyResolver
public class SPAssemblyResolver : IAssembliesResolver
{
public ICollection<Assembly> GetAssemblies()
{
return new List<Assembly> { Assembly.GetExecutingAssembly() };
}
}
WebAPIVirtualPathProvider
Same as SignalRVirtualPathProvider shown in the post.
NEW ISSUE
The only problem with this approach is ScriptResource.axd and WebResource.axd now break when SP references them in a page. I tried to add an ignore route:
RouteTable.Routes.Add(new Route("{resource}.axd", new StopRoutingHandler()));
But I keep getting 401 Unauthorized. Removing the module clears the error, so I guess we're still lacking one last piece of the puzzle.
Upvotes: 6
Views: 7010
Reputation: 200
Yes, the same approach should work.
Create a web api project and check the app init part - then follow my blog post you referenced already.
Btw: Ask at sharepoint.stackexchange.com - maybe someone has a better solution.
Upvotes: 1