how to enable and disable button based on user role?

前端 未结 6 1846
予麋鹿
予麋鹿 2021-01-13 20:22

I have a role called \'member\' and another \'admin\' in Asp.Net website.

I did before, that button should be visible or not and i am successful in that,but,i am not

6条回答
  •  野的像风
    2021-01-13 21:03

    You have to set the Button.Enabled property value to according to the HttpContext.Current.User.IsInRole("admin") function returned value.

    Either in html:

    Or in code behind:

    Button.Enabled = HttpContext.Current.User.IsInRole("Admin");
    

提交回复
热议问题