Solved

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

Posted on 2006-06-14
5
1,380 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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now