Hi, i use Xamarin Forms for Visual studio 2015 with .net 4.6 version.
What to apply some custom action filter attribute, which must check user permissions for action, is sample.
I have TestPage.xaml, with some actionst inside, and this page load first in app.
Before page load, and before any action inside this page a invoked, i what to check user to permission (user name and permission i get from API service and save it in app static context)
i create C# class :
public class CustomActionAttribute : Attribute
{
public class CustomActionAttribute ()
{
if(!App.StaticContext.IsUserGranted)
new AccessDeniedPage();
}
}
Logic is simple, attribute check if user granted for this action he don`t do anything, if not, he redirect user to another page (AccessDenied)
and in my TestPage.xaml.cs i use this
public partial class TestPage : ContentPage
{
[CustomActionAttribute]
public
{
InitializeComponent();
var response = App.client.GetAsync(LoginModel.ApiUrl+ "/api/test/get?id=5").Result;
var content = response.Content.ReadAsStringAsync().Result;
this.TestMessageContainer.Text = content;
}
}
but my attribute action dont invoked when TestPage is loaded.
What im doing wrong ?