Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 11th, 2004, 04:07 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Authentication and Role-Based Security

Hi,
I'm using Daniel Cazzulino's excellent book "Beginning C# Web Applications with Visual Studio .NET". In his example in chapter 10 he creates a GenericPrincipal containg the role of a user (which will later show or hide a link to an admin page). Here is a code snippet :

    ConfigurationSettings.AppSettings["cnFriends.ConnectionString"]);
sql = "SELECT IsAdministrator FROM [User] WHERE UserId='{0}'";
sql = String.Format(sql, id);
cmd = new SqlCommand(sql, con);
con.Open();

object admin = cmd.ExecuteScalar();

// Was it a valid UserID?
if (admin != null)
  {
  GenericPrincipal ppal;
  string[] roles;

    // If IsAdministrator field is true, add both roles
    if (((bool)admin) == true)
        {
        roles = new string[] {"User", "Admin"};
        }
     else
        {
        roles = new string[] {"User"};

........

his role is stored as a boolean and inspected as such. But I have several roles which are probably better stored as int. Has anybody got any advice how I might achieve this? Something like :

int admin = cmd.ExecuteScalar();
.....
if (admin == 1){roles = new string[] {"User", "Approver","Admin"};}
elsif (admin == 2){roles = new string[] {"User", "Approver"};}
else {roles = new string[] {"User"};}

Maybe??


Similar Threads
Thread Thread Starter Forum Replies Last Post
Role based security tsimsha ASP.NET 2.0 Basics 4 May 6th, 2008 11:41 AM
Code Access Security & Role Based Security robzyc C# 6 April 11th, 2008 02:31 AM
Tag library for field level role based security mmalik_altaf Pro JSP 0 June 7th, 2006 05:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.