I have the following API controller:
public class TestController : ApiController
{
[HttpPost]
[APIAuthorizeAttribute]
public IQueryable<Computers> ListOfComputersInFolder(Guid folderId)
{
return GetListOfComputersForFolder(folderId);
}
}
And here is my basic one APIAuthorizeAttribute.
public class APIAuthorizeAttribute : System.Web.Http.AuthorizeAttribute
{
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
var Request = System.Web.HttpContext.Current.Request;
var folderId = Request.RequestContext.RouteData.Values["folderId"] ?? Request.Params["folderId] as string;
if(null == folderId)
{
folderId = actionContext.ControllerContext.RouteData.Values["folderId"];
}
base.OnAuthorization(actionContext);
}
}
The problem I am facing is that it is folderIdgetting out of null in the onAuthorize method. (I founded the collector in this code).
It seems to me that this should work, but I cannot understand. Any ideas on what I'm doing wrong, and how do I need to get the published parameter?
Edit: I tried reading the message data directly with the following:
using (StreamReader inputStream = new StreamReader(request.InputStream))
{
output = inputStream.ReadToEnd();
}
request.InputStream.Position = 0;
Which receives me JSON-formatted message data that I could parse, but then my call never does it. In the response, I get the following exception:
<h2>500 - Internal server error.</h2>
<h3>There is a problem with the resource you are looking for, and it cannot be displayed.
at System.Json.JXmlToJsonValueConverter.JXMLToJsonValue(Stream jsonStream, Byte[] jsonBytes)\u000d\u000a at System.Net.Http.Formatting.JsonMediaTypeFormatter.<>c__DisplayClass7.<OnReadFromStreamAsync>b__6()\u000d\u000a at System.Net.Http.Internal.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"}
EDIT:
, , ApiController, System.Web.Http.AuthorizeAttribute HttpPost ( HttpGet). .