Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModules [SupportedModules("XXX")] not working with Service Framework (WebAPI) [SupportedModules("XXX")] not working with Service Framework (WebAPI)
Previous
 
Next
New Post
12/7/2015 5:25 PM
 

Trying to implement a WebAPI through DNN7 but it turned out not to be to easy. The work if I use the [AllowAnonymous] or no decorations at all (logged in as Host) but if I start to decorate my controllers/methods with stuff like [SupportedModules("ExploreSettings")] it never seem to work. In fact, it doesn't even work with the sample provided by Scott Schlesier here:

http://www.dnnsoftware.com/community-blog/cid/145174/services-framework-with-meat

No matter if I am logged in as host standing on a page with the ExploreSettings on it I will still get authentication error and am being asked for credentials. I've tried to amp up the loggin in log4net but can't really find anything useful there (log below). Any ideas? Routes etc should be fine as they do work with  [AllowAnonymous]

Are there some actual documentation regarding the Service Framework or is a few year old blog posts all there is? 

 

2015-12-07 23:10:58,907 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.MessageHandlers

2015-12-07 23:10:58,912 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.MessageHandlers

2015-12-07 23:10:58,915 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.MessageHandlers

2015-12-07 23:10:58,919 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.MessageHandlers

2015-12-07 23:10:58,923 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Request http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings

2015-12-07 23:10:58,936 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Controllers Route='controller:Settings,action:HostSettings'

2015-12-07 23:10:58,998 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Controllers Settings

2015-12-07 23:10:59,002 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Controllers

2015-12-07 23:10:59,006 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Controllers

2015-12-07 23:10:59,014 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Controllers ExploreSettings.SettingsController

2015-12-07 23:10:59,017 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Controllers ExploreSettings.SettingsController

2015-12-07 23:10:59,021 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Controllers

2015-12-07 23:10:59,028 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Action

2015-12-07 23:10:59,068 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Action Selected action 'HostSettings()'

2015-12-07 23:10:59,093 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Filters

2015-12-07 23:10:59,105 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Net.Http.Formatting Type='HttpError', formatters=[JsonMediaTypeFormatterTracer, XmlMediaTypeFormatterTracer, FormUrlEncodedMediaTypeFormatterTracer, FormUrlEncodedMediaTypeFormatterTracer, MediaTypeFormatterTracer]

2015-12-07 23:10:59,128 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Net.Http.Formatting Obtaining formatter of type 'JsonMediaTypeFormatter' for type='HttpError', mediaType='application/json; charset=utf-8'

2015-12-07 23:10:59,132 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Net.Http.Formatting Will use same 'JsonMediaTypeFormatter' formatter

2015-12-07 23:10:59,136 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Net.Http.Formatting Selected formatter='JsonMediaTypeFormatter', content-type='application/json; charset=utf-8'

2015-12-07 23:10:59,142 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Filters

2015-12-07 23:10:59,155 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Controllers

2015-12-07 23:10:59,160 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Request Content-type='application/json; charset=utf-8', content-length=unknown

2015-12-07 23:10:59,163 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.MessageHandlers

2015-12-07 23:10:59,166 [IMPROWISE_MBP15][Thread:44][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.MessageHandlers

2015-12-07 23:10:59,182 [IMPROWISE_MBP15][Thread:34][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.MessageHandlers

2015-12-07 23:10:59,190 [IMPROWISE_MBP15][Thread:34][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.MessageHandlers

2015-12-07 23:10:59,205 [IMPROWISE_MBP15][Thread:34][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Net.Http.Formatting Value='System.Web.Http.HttpError', type='HttpError', content-type='application/json; charset=utf-8'

2015-12-07 23:10:59,221 [IMPROWISE_MBP15][Thread:34][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Net.Http.Formatting

2015-12-07 23:10:59,231 [IMPROWISE_MBP15][Thread:34][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Controllers

2015-12-07 23:10:59,235 [IMPROWISE_MBP15][Thread:34][INFO] DotNetNuke.Web.Api.TraceWriter -  GET http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings System.Web.Http.Controllers


 
New Post
12/7/2015 5:37 PM
 

Also, how are we supposed to send ModuleId and TabId in the request to the Service Framework / WebAPI? Is it supposed to handle itself when logged in to a DNN portal? I notice that when logged in the user info seem to be sent along by default, so that I can only access the WebAPI when logged in, but what I can see nothing with regards to ModuleId or TabId is send along except for LastPageId which could be TabId but not sure?

Also noted that, a bit strange, my routes, despite working (sometimes) does not show up as being mapped in the log:

 

2015-12-07 23:10:50,372 [IMPROWISE_MBP15][Thread:12][TRACE] DotNetNuke.Web.Api.Internal.ServicesRoutingManager - Mapping route: MyServices-default-0 @ DesktopModules/MyServices/API/{controller}/{action}

2015-12-07 23:10:50,377 [IMPROWISE_MBP15][Thread:12][TRACE] DotNetNuke.Web.Api.Internal.ServicesRoutingManager - Mapping route: CoreMessaging-default-0 @ DesktopModules/CoreMessaging/API/{controller}/{action}

2015-12-07 23:10:50,380 [IMPROWISE_MBP15][Thread:12][TRACE] DotNetNuke.Web.Api.Internal.ServicesRoutingManager - Mapping route: DigitalAssets-default-0 @ DesktopModules/DigitalAssets/API/{controller}/{action}

2015-12-07 23:10:50,383 [IMPROWISE_MBP15][Thread:12][TRACE] DotNetNuke.Web.Api.Internal.ServicesRoutingManager - Mapping route: SocialGroups-default-0 @ DesktopModules/SocialGroups/API/{controller}/{action}

2015-12-07 23:10:50,385 [IMPROWISE_MBP15][Thread:12][TRACE] DotNetNuke.Web.Api.Internal.ServicesRoutingManager - Mapping route: Journal-default-0 @ DesktopModules/Journal/API/{controller}/{action}

2015-12-07 23:10:50,388 [IMPROWISE_MBP15][Thread:12][TRACE] DotNetNuke.Web.Api.Internal.ServicesRoutingManager - Mapping route: MemberDirectory-default-0 @ DesktopModules/MemberDirectory/API/{controller}/{action}

2015-12-07 23:10:50,391 [IMPROWISE_MBP15][Thread:12][TRACE] DotNetNuke.Web.Api.Internal.ServicesRoutingManager - Mapping route: Taxonomy-default-0 @ DesktopModules/Taxonomy/API/{controller}/{action}

2015-12-07 23:10:50,394 [IMPROWISE_MBP15][Thread:12][TRACE] DotNetNuke.Web.Api.Internal.ServicesRoutingManager - Mapping route: InternalServices-default-0 @ DesktopModules/InternalServices/API/{controller}/{action}

2015-12-07 23:10:50,398 [IMPROWISE_MBP15][Thread:12][TRACE] DotNetNuke.Web.Api.Internal.ServicesRoutingManager - Mapping route: ExploreSettings-default-0 @ DesktopModules/ExploreSettings/API/{controller}/{action}

 
New Post
12/8/2015 3:33 AM
 
Hi Patrick.

For all WebAPI requests that are decorated by [DnnAuthorize] and etc..
Each request must contain following headers: ModuleId, TabId, RequestVerificationToken

JavaScript example:
var _sf = $.ServicesFramework(YourModuleID);
var req = {
method: 'GET',
url: 'http://dnn7.improwise.local/DesktopModules/ExploreSettings/API/Settings/HostSettings',
headers: {
'Content-Type': 'application/json',
'ModuleId': _sf.getModuleId(), //current module id
'TabId': _sf.getTabId(), //current module tab id
'RequestVerificationToken': _sf.getAntiForgeryValue(), 
}
};

 

Reference:
http://www.dnnsoftware.com/wiki/services-framework-security-aspnet-mvc 
http://www.dnnsoftware.com/forums/forumid/89/postid/523271/scope/posts

 
New Post
12/8/2015 5:00 AM
 

Thank you Barry for responding. It's a bit stupid that the only link that seem to contain relevant information about this is marked with "This has now been superceded by a WebAPI implementation in DotNetNuke 7.0.0" which at least made me not read any further and thus missing out on important information therein. 

Are the authentication stuff the same from the old now depreciated MVC version, ie that most info in the first link are still relevant? 

How are the combination of TabId and ModuleId used, are both required all the time? 

 
New Post
12/8/2015 9:51 AM
 

You can also let the setModuleHeaders function of the ServicesFramework to set the headers for you:

 

self.getIndividualsInPositions = function (pageNumber, pageSize, positionList) {
            self.LoadingData(true);
            $.ajax({
                type: "POST",
                cache: false,
                url: baseServicepath + "GetIndividualsInPositions",
                beforeSend: _sf.setModuleHeaders,
                data: {
                    PositionList: positionList,
                    WhereClause: self.WhereClauseFilter(),
                    OnlyIncludedInDirectory: !self.TabState[3].IncludeNotInDirectory(),
                    PageIndex: pageNumber - 1,
                    PageSize: pageSize
                }
            }).done(function (result) { . . .

 

 

In your services controller methods, the ModuleID, TabID, PortalID, etc.  will be available on the ActiveModule object.

 

As for the SupportedModules attribute, I initially had the same problems with this until I realized that the value should be the name of the project's DesktopModules folder, not the project's namespace:

 

// Path is DesktopModules/WESNet_FamilyDirectory/API/FamilyDirectoryServices/{action}
    [SupportedModules("WESNet_FamilyDirectory")]
    [DnnModuleAuthorize(AccessLevel = SecurityAccessLevel.View)]
    public class FamilyDirectoryServicesController : DnnApiController
    {


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModules [SupportedModules("XXX")] not working with Service Framework (WebAPI) [SupportedModules("XXX")] not working with Service Framework (WebAPI)


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out