Solved

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

Posted on 2006-06-14
5
1,386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
VIkasumit earned 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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