Hi David,
Please answer completely because I tested but I couldn't get a good result.
Give me a correct URL.
Someone has answered it but it's not useful for me.
so your controller should look something like this:
[PluginController("ReplyApi")]
public class ReplyApiController : UmbracoAuthorizedJsonController
{
[HttpPost]
public bool ReplyMessage(string message)
{
//Send your message here
//Maybe return if it was a success - thus the bool return value, can also be void or what you need
}
}
Also your controller is in the wrong place. AppPlugins only contains all the angularjs stuff. Instead put it in AppCode or in a Controller folder in your solution.
Second the path to your api controller is wrong.
I would suggest to use ServerVariables for these kind of paths.
You can add ServerVariables during application startup:
public class StartUp : IApplicationEventHandler
{
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ServerVariablesParser.Parsing += ServerVariablesParser_Parsing;
}
void ServerVariablesParser_Parsing(object sender, Dictionary<string, object> e)
{
if(HttpContext.Current == null) throw new InvalidOperationException("HttpContext is null");
var urlHelper = new UrlHelper(new RequestContext(new HttpContextWrapper(HttpCo
ntext.Current), new RouteData()));
var dict = new Dictionary<string, object>();
dict.Add("replyBaseUrl", urlHelper.GetUmbracoApiServiceBaseUrl<ReplyApiController>(controller => controller.ReplyMessage("")));
if (!e.Keys.Contains("replyController"))
{
e.Add("replyController", dict);
}
}
}
With that you can use the path in your angular controller like so:
I've added some input on the StackOverflow post. I'd also recommend David's suggestion of using UmbracoAuthorizedJsonController instead of a SurfaceController.
Umbraco cannot find the route in backoffice
Please look at my question that is in stackoverflow website Umbraco cannot find the route in backoffice
Help me, please.
Hi Jahan,
SurfaceController are used only for frontend stuff in umbraco.
If you want to use a controller in the backoffice have a look at UmbracoAuthorizedApiController.
These are used in the backoffice to handle data fetching/updating.
Also have a look at the PluginController attribute
Regards David
Hi David, Please answer completely because I tested but I couldn't get a good result. Give me a correct URL. Someone has answered it but it's not useful for me.
Hi Jahan,
so your controller should look something like this:
Also your controller is in the wrong place. AppPlugins only contains all the angularjs stuff. Instead put it in AppCode or in a Controller folder in your solution.
Second the path to your api controller is wrong. I would suggest to use ServerVariables for these kind of paths.
You can add ServerVariables during application startup:
With that you can use the path in your angular controller like so:
So your http call will look like this:
Hope that helps
THANK YOU VERY MUCH, David.
Hi David, Please visit this link. He answered simply and it's correct. What's your idea about it?
I've added some input on the StackOverflow post. I'd also recommend David's suggestion of using UmbracoAuthorizedJsonController instead of a SurfaceController.
Thank you.
is working on a reply...