Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

why do i get this error when trying to make a hashtable?

Posted on 2006-06-14
5
Medium Priority
?
1,390 Views
Last Modified: 2012-06-27
Hello,

I have the following code below.  However, when i try to run it, i get this error:
CS0246: The type or namespace name 'HashTable' could not be found (are you missing a using directive or an assembly reference?)


Does anyone know why, or how to fix it?

Thanks



<%@ Application Language="C#" debug="true"%>
<%@ Import Namespace="System.Security.Principal" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Collections.Specialized" %>
<%@ Import Namespace="System.Reflection" %>


<script runat="server">



override void Init()
{
  colRoles = new HashTable();

  string[] arrJaneRoles = new string[]{ "Supervisors", "Engineers" };
  colRoles["yourdomain\jane"] = arrJaneRoles;
  string[] arrGeorgeRoles = new string[]{ "Engineers" };
  colRoles["drew-duvljdm2b3\george"] = arrGeorgeRoles;
}

void WindowsAuthentication_Authenticate( object s, WindowsAuthenticationEventArgs e ) {
      e.User = new GenericPrincipal( e.Identity, colRoles(e.Identity.Name.ToLower()) );
}
   
    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup

    }
   
    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }
       
    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends.
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer
        // or SQLServer, the event is not raised.

    }
       
</script>
0
Comment
Question by:alexthecodepoet
  • 3
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
VIkasumit earned 2000 total points
ID: 16909419
Hi,

you code is little wrong,

override void Init()
{
  colRoles = new HashTable();

  string[] arrJaneRoles = new string[]{ "Supervisors", "Engineers" };
  colRoles["yourdomain\jane"] = arrJaneRoles;
  string[] arrGeorgeRoles = new string[]{ "Engineers" };
  colRoles["drew-duvljdm2b3\george"] = arrGeorgeRoles;
}


In this you doesn't declare colRoles ?

first declare variable colRoles as new HashTable than try to initialize it.
also,
  colRoles["yourdomain\jane"] = arrJaneRoles;
will produce error as you first need to add a Key to hashtable colRoles before assigning value to it..

Please read MSDN tutorial or any other, Or Maybe I miss your complete code...

hope that help

VIkasumit
I thin
0
 

Author Comment

by:alexthecodepoet
ID: 16909424
Hi,

Thanks for helping me with this.

I will use a simpler version of my code:

<%@ Application language="C#" debug="true" %>
<%@ Import Namespace="System.Security.Principal" %>
<%@ Import Namespace="System.Collections" %>

<script language="C#" runat="server">

HashTable colRoles;

override void Init()
{
  Hashtable colRoles = new HashTable();

  string[] arrJaneRoles = new string[]{ "Supervisors", "Engineers" };
  colRoles["yourdomain\jane"] = arrJaneRoles;
  string[] arrGeorgeRoles = new string[]{ "Engineers" };
  colRoles["drew-duvljdm2b3\george"] = arrGeorgeRoles;
}

void WindowsAuthentication_Authenticate( object s, WindowsAuthenticationEventArgs e ) {
      e.User = new GenericPrincipal( e.Identity, colRoles(e.Identity.Name.ToLower()) );
}

</Script>


I get the sam error.
0
 
LVL 4

Expert Comment

by:VIkasumit
ID: 16909949
Hi,

Sorry, But I am Vb.NET programmer in Visual Studio :) so doesn't master this method of coding, Though can you pin point the line in which you are getting error...

Also i still cannot see the colRoles.Add () function call to add new KEY like yourdomain\jane  ....

VIkasumit
0
 

Author Comment

by:alexthecodepoet
ID: 16909967
this error was happening for two reasons.

1) its Hashtable not HashTable  

I also needed this:

void WindowsAuthentication_Authenticate( object s, WindowsAuthenticationEventArgs e ) {
      e.User = new GenericPrincipal( e.Identity, (string[])(colRoles[e.Identity.Name.ToLower()]));
}

thanks for attempting to help guys
0
 
LVL 4

Expert Comment

by:VIkasumit
ID: 16910893
Hi,

Its my pleasure ... But I feel sorry that I cannot help you out :)

But Thanks for accepting it, though you can delete the question in this situation.

Though I still wonder how can that be Hashtable than HashTable :) as per ms guideline (maybe I don't know them correctly)

VIkasumit
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Loops Section Overview
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question