Welcome to the Community Exchange, a place where community members can exchange questions and answers related to DotNetNuke. If you would like more info about the Community Exchange, please visit this page in our Wiki.
I'm trying to build a RESTful API with DNN 6.2's web services. REST calls for newly created items to be called with a PUT verb.
I'm using my router to send this to the correct function. This works just fine:
routeManager.MapRoute(
"Revolution/Engine"
,
"{controller}/{id}"
new
{ controller =
"TriggerPoints"
, action =
"UpdateTriggerPoint"
, },
{ httpMethod =
HttpMethodConstraint(
"PUT"
) },
[] {
"Engine"
});
When my UpdateTriggerPoint is fired, I'm having an issue:
[ValidateInput(
false
)]
[AcceptVerbs(HttpVerbs.Put)]
public
ActionResult UpdateTriggerPoint(Models.TriggerPoint triggerPoint)
{
if
(ModelState.IsValid)
// save to database here
// problem: triggerPoint only contains empty values!
}
return
Json(
true
);
The data is nowhere to be seen once the function hits. How does one read the contents of a PUT verb with the new web services framework?
One more thing to try in the morning:http://stackoverflow.com/questions/6369541/reading-put-request-body - Lucas Jans 8/1/2012
The closest thing I can find to an answer is this: http://stackoverflow.com/questions/10683438/mvc3-rest-service-how-do-i-access-the-request-body-content-for-a-put-or-post-r but how does that translate to DNN since I can't modify the asax? - Lucas Jans 8/1/2012
I'm am not at all sure why the put data is is not bound properly. If you can successfully POST the data, the model binding for a put should be the same.
IIS often needs to be configured to support PUTs. But if that was the problem I would expect that your action would not be called at all. The core of DNN will not ever be using PUTs for this reason. However, if you can configure IIS everywhere your service is deployed then PUTs can work for you.
If you do find you need a custom model binder for some reason, you should register it inside the route mapper. Routes are re-mapped when new portals are added to a DNN installation, so you should include a test to see if your model binder is already present before registering it to ensure you don't register multiple model binders.
My understanding is that webDAV will interfere with puts in a default 7.5 installation. It is not likely the problem you currently face, but a problem for widespread deployment. - Scott S 8/1/2012
I believe IIS 7 and up support PUT by default, but I'm not sure about IIS 6. That being said, using request filters, someone can disable any verb. I can see how you wouldn't want to depend on that.http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/verbs/addI'm using Backbone which uses the PUT verb by default. If POST does work, I can create a psuedo verb (like PHP folks have to) by adding the attribute _method = PUT.I will test to see if the POST method binds the data to the attribute. If not, it looks like I have two options. A custom model binder (which I'm a bit fuzzy on implementing) or reading the raw stream Request.InputStream.Position = 0; var triggerPointJSON = new StreamReader(Request.InputStream).ReadToEnd();And then serializing it. - Lucas Jans 8/1/2012
My trouble isn't returning data but accessing the data that is "PUT." When I access the triggerPoint parameter, it's blank, but in examples I've seen on the web it contains the PUT data. - Lucas Jans 8/1/2012
You have already flagged this post. Clicking "Remove Flag" below will remove your flag, thus reducing the count by one as well.