Adding roles and permissions to a traditional web app?http://forums.asp.net/t/1798645.aspx/1?Adding+roles+and+permissions+to+a+traditional+web+app+Tue, 01 May 2012 06:07:18 -040017986454958960http://forums.asp.net/p/1798645/4958960.aspx/1?Adding+roles+and+permissions+to+a+traditional+web+app+Adding roles and permissions to a traditional web app? <p>We have a regular webforms asp.net application and we'd like to implement roles and permissions to it.</p> <p>Essentially, the roles will allow the users to be able to see X webforms and Y controls within those webrforms. For example, there's a webform called Users.aspx. So there could be role VIEWER that can see the webform Users.aspx but they cannot add/modify anything (ie. textboxes would be read-only and submit button is not visible)</p> <p>What would be the best way to do this? I was thinking of having a Role table and then having a Privileges with the webforms that a certain role can see and the controls (within that webform) that this role can see. So the privileges table could have a record for VIEWER, the webform this user would be able to see, and then the controls (within the webform) that this user could alter.</p> <p>Is this possible?</p> <p>Thanks.</p> 2012-04-30T20:47:56-04:004958985http://forums.asp.net/p/1798645/4958985.aspx/1?Re+Adding+roles+and+permissions+to+a+traditional+web+app+Re: Adding roles and permissions to a traditional web app? <p>Why don't you use .net membership?</p> 2012-04-30T21:18:39-04:004958994http://forums.asp.net/p/1798645/4958994.aspx/1?Re+Adding+roles+and+permissions+to+a+traditional+web+app+Re: Adding roles and permissions to a traditional web app? <p>I used and i made my Login system so, there were rolls i made..</p> <p>Concentrate the Scenario:</p> <p>its my Login Table</p> <p>UserName ---- Password ---- CampusCode</p> <p>MyName &nbsp; ---- 123PW ------- NK</p> <p>On login page I Coded like this</p> <pre class="prettyprint">str = &quot;select * from login where Username =@username and Password =@password&quot;; cmd = new SqlCommand(str, con); cmd.Parameters.AddWithValue(&quot;@username&quot;, txtUsername.Text); cmd.Parameters.AddWithValue(&quot;@password&quot;, txtPass.Text); sdr = cmd.ExecuteReader(); if (sdr.Read()) { Session[&quot;Campus&quot;] = sdr[&quot;CampusCode&quot;].ToString(); // then Responce.reditect to another page then</pre> <p>So I took value of Campus By Session now , on 2nd Page On top right i put the Label and Put the Session value of Campus.</p> <p>then on page load i Programed like</p> <pre class="prettyprint"> if (Label.Text = "NK") { panel1.visible = false; } else if ( Label.Text = "2nd Campus etc") { Panel2.Visible = true; }</pre> <pre class="prettyprint"><br /><br /></pre> <p>More over you will have to work hard for it. but you can do better in asp.net Membership system.</p> 2012-04-30T21:28:26-04:004959260http://forums.asp.net/p/1798645/4959260.aspx/1?Re+Adding+roles+and+permissions+to+a+traditional+web+app+Re: Adding roles and permissions to a traditional web app? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>vmhatup</h4> the roles will allow the users to be able to see X webforms and Y controls within those webrforms. </blockquote> <p></p> <p>Roles based Authorization in ASP.NEt -&nbsp;<a href="http://msdn.microsoft.com/en-us/library/ff647401.aspx">http://msdn.microsoft.com/en-us/library/ff647401.aspx</a>&nbsp;</p> <p>for webforms you can do authorization, but for specific parts on page, you might need to write code to load those controls based on roles...</p> <p>Thanks,</p> <p></p> 2012-05-01T05:48:08-04:004959294http://forums.asp.net/p/1798645/4959294.aspx/1?Re+Adding+roles+and+permissions+to+a+traditional+web+app+Re: Adding roles and permissions to a traditional web app? <p>Use ASP.NET membership provider and controls on a page can be controlled using role based authorization for example:</p> <pre class="prettyprint">protected void Page_Load(object sender, EventArgs e) { if (!Roles.IsUserInRole(&quot;Admin&quot;)) { MenuItemCollection menuItems = mTopMenu.Items; MenuItem adminItem = new MenuItem(); foreach (MenuItem menuItem in menuItems) { if (menuItem.Text == &quot;Roles&quot;) adminItem = menuItem; } menuItems.Remove(adminItem); someothercontrol.Visible=True; } }</pre> <p><br> Role Based Authorization:</p> <p><a href="http://www.asp.net/web-forms/tutorials/security/roles/role-based-authorization-cs">http://www.asp.net/web-forms/tutorials/security/roles/role-based-authorization-cs</a></p> 2012-05-01T06:07:18-04:00