Hi, I found a very interesting thing.
When I'll use [AbpAuthorize] attribute on any application service and then I'll call this service direct through the JavaScript, like this:
abp.services.app.machine.getStatusAsync({
id: machineId
}).done(function (data) {
// some code
});
Then the data.result will be always "No user logged in!". But user is logged in and he has full permissions.
But, when I'll call through the MVC controller the same app service still with the [AbpAuthorize] attribute, like this: JavaScript
$.get(url, { id: machineId }).done(function (response) {
abp.message.info(response.result);
});
MVC Controller
public async Task<JsonResult> GetStatus(int id)
{
var input = new GetMachineStatusInput
{
Id = id
};
var output = await _machineAppService.GetStatusAsync(input);
return Json(new MvcAjaxResponse(output.Response.Status), JsonRequestBehavior.AllowGet);
}
Then the expected result will be returned.
Why this is happening? How I can resolve this?
5 Answer(s)
-
0
Hi, I am not sure about this, but have you tried [Abp.WebApi.Authorization.AbpApiAuthorize] ?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi, [Abp.WebApi.Authorization.AbpApiAuthorize] attribute is for usage with Web API, not for application services. See: [http://aspnetboilerplate.com/Pages/Documents/Authorization])
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Interesting.. How did you inject MachineAppService to your controller? Did you inject the app service interface or implementation?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Here is my machine controller:
public class MachinesController : AdminControllerBase { private readonly IMachineAppService _machineAppService; public MachinesController(IMachineAppService machineAppService) { _machineAppService = machineAppService; } public async Task<JsonResult> GetStatus(int id) { var input = new GetMachineStatusInput { Id = id }; var output = await _machineAppService.GetStatusAsync(input); return Json(new MvcAjaxResponse(output.Response.Status), JsonRequestBehavior.AllowGet); } }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
I could not understand the reason. Because, I have used [AbpAuthorize] for many app services and they are just working. I want to help you but I can not repeat the problem.
BTW, why don't you use abp.ajax instead of $.get?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)