I have another issue I am trying to iron out and in the process of trying to simplify the issue I've created the most simple UmbracoAuthorizedJsonController implementation as follows:
[PluginController("MyPlugIn")]
public class DataMigratorController : UmbracoAuthorizedJsonController
{
[HttpGet]
public object HelloWorld()
{
return new { Message = "Hello World" };
}
}
If I browse to /umbraco/backoffice/Myplugin/DataMigrator/HelloWorld before login I get the expected 401 Unauthorized - great, that's what I want! However, when I login to Umbraco and then load the same path I get a 417 Missing token error returned. I've read numerous posts on here about deleting cookies, clearing cache and incrementing the ClientDependency version number and none have helped.
Thanks Dave, I double checked that when I setup my test controller. Turns out the issue kind of wasn't an issue but the method of attempting to verify the controller was working - it needed to be called from Angular and not a browser!
If I setup a quick angular controller to call this API it works!
There is a note in the source for the UmbracoAuthorizedJsonController stating
Inheriting from this controller means that ALL of your methods are JSON methods that are called by Angular, methods that are not called by Angular or don't contain a valid csrf header will NOT work.
So, that's one problem solved and I now know that I can't test UmbracoAuthorizedJsonController based implementations using browser based GET requests. Hopefully, this post saves someone else some time!
UmbracoAuthorizedJsonController - 417 Missing token
I have another issue I am trying to iron out and in the process of trying to simplify the issue I've created the most simple
UmbracoAuthorizedJsonController
implementation as follows:If I browse to
/umbraco/backoffice/Myplugin/DataMigrator/HelloWorld
before login I get the expected401 Unauthorized
- great, that's what I want! However, when I login to Umbraco and then load the same path I get a417 Missing token
error returned. I've read numerous posts on here about deleting cookies, clearing cache and incrementing the ClientDependency version number and none have helped.Not sure where to go from here?
Umbraco v7.5.8
I have only 4 cookies set when this occurs:
Hi Simon,
The HttpGet attribute can be the wrong one. There is one in the System.Web.Mvc namespace and one in the System.Web.Http.
In Web API you need to use the last one. I had a similar issue once where I used the wrong one.
Dave
Thanks Dave, I double checked that when I setup my test controller. Turns out the issue kind of wasn't an issue but the method of attempting to verify the controller was working - it needed to be called from Angular and not a browser!
So I learnt something new here...
If I setup a quick angular controller to call this API it works!
There is a note in the source for the
UmbracoAuthorizedJsonController
statingSo, that's one problem solved and I now know that I can't test
UmbracoAuthorizedJsonController
based implementations using browser basedGET
requests. Hopefully, this post saves someone else some time!Thanks you already save my time in it ^_^.
is working on a reply...