c# - ASP.NET WebForms - How to Authorise access to a page -


in latest asp.net webforms application no longer user rolemanager etc (as far can tell) how authorize access webpage particular role?

in mvc use authorize attribute doesn't exist in webforms @ loss - ideas?

try code on login pass role formsauthenticationticket

formsauthenticationticket ticket = new formsauthenticationticket(1, username.text, datetime.now, datetime.now.addminutes(2880), false, role, formsauthentication.formscookiepath);             string hash = formsauthentication.encrypt(ticket);             httpcookie cookie = new httpcookie(formsauthentication.formscookiename, hash);              if (ticket.ispersistent)             {                 cookie.expires = ticket.expiration;             }             response.cookies.add(cookie);             response.redirect(formsauthentication.getredirecturl(username.text, false)); 

on particular webform on page_load event retrieve role

protected void page_load(object sender, eventargs e)     {               formsidentity id = (formsidentity)httpcontext.current.user.identity;              formsauthenticationticket ticket = id.ticket;              string userdata = ticket.userdata;              string[] temp = userdata.split(',');              role=temp[0];          if (role!="owner")          {              response.write("............");          }     } 

if want authorization on folder level instead of checking role on webform specify role in web.config file of folder

 <authorization>   <allow  roles="owner"/>   <deny users="*"/> </authorization> 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -