Solved

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

Posted on 2006-06-14
5
1,383 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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