When I call a DNN WebAPI service that has an AllowAnonymousAttribute from another application it works just fine. Actually it's as simple as can be to get back fully typed objects!
However, I am unable to use the DNN authentication attribute successfully.
Here is the code in question (I'm sorry, I cant see how to format it):
Code:
Option Infer On
Imports System.Collections
Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports System.Net.Http
Imports System.Web.Http
Imports DotNetNuke.Entities.Portals
Imports DotNetNuke.Entities.Users
Imports DotNetNuke.Security.Roles
Imports DotNetNuke.Web.Api
Namespace MyServices
Public Class RoleSubscriptionController
Inherits DnnApiController
<allowanonymous,> _</allowanonymous,>
Public Function GetTestData() As HttpResponseMessage
Dim result As New List(Of RoleDTO)
result.Add(New RoleDTO With {.RoleID = 11, .Subscribed = True})
result.Add(New RoleDTO With {.RoleID = 12, .Subscribed = True})
result.Add(New RoleDTO With {.RoleID = 13, .Subscribed = False})
Return Request.CreateResponse(HttpStatusCode.OK, result)
End Function
#Region "Nested type: RoleDTO"
Public Class RoleDTO
Public Property RoleID() As Integer
Public Property Subscribed() As Boolean
End Class
#End Region
End Class
End Namespace
[code]
And the simple consuming code:
[code]
Imports System.Net.Http
Imports System.Net.Http.Headers
Public Class OwnersClubClient
Private _Client As HttpClient
Private _Handler As New HttpClientHandler
Public Async Sub Test()
_Handler.Credentials = New System.Net.NetworkCredential("admin", "password")
_Client = New HttpClient(_Handler)
Dim response = Await _Client.GetAsync("http://www.dnndev.me/DesktopModules/MyServices/API/RoleSubScription/GetTestData")
response.EnsureSuccessStatusCode() ' Throw on error code.
Dim products As IEnumerable(Of RoleDTO) = Await response.Content.ReadAsAsync(Of IEnumerable(Of RoleDTO))()
Debug.Print(products.Count)
End Sub
Public Class RoleDTO
Public Property RoleID() As Integer
Public Property Subscribed() As Boolean
End Class
End Class