Solved

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

Posted on 2006-06-14
5
1,387 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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