sarkaft

sarkaft

  • NA
  • 6
  • 6.9k

The type or namespace name 'User' could not be found (are you missing a using directive or an assembly reference?)

Jan 21 2012 10:12 AM
I have created a website from File->new-> Web Site. i am trying to go to mydomain.com/piro/admin/login.aspx i have created a class named User.cs, this class is in the mysomain.com/piro/App_Code folder.
when i run this web site locally, everything works fine, but when i move my files to the server i get the error on the User type. i tried to deploy my website, to copy my website, to create new on ftp website but nothing works, i have searched for a solution, but couldn't find any answer for my problem. can any one please help..! here is my code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class admin_login : System.Web.UI.Page
{
 
protected void Page_Load(object sender, EventArgs e)
{
   
Label1.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
   
User user = new User();
    user
.username = txtUsername.Text;
    user
.password = txtPassword.Text;

   
User login = loggInn(user);
   
if (login == null)
   
{
       
Label1.Text = "User name or password is wrong";
   
}
   
else
   
{
       
Session["userName"] = user.username;
       
Session["lastvisit"] = login.lastvisit;
       
Session["systemUser"] = login.role;
       
// Session["rolle"] = godkjent.rolle;
       
Response.Redirect("Default.aspx");
   
}
   
//string loggInn = checkUserLinq(user);

   
// string check = checkUser(user);
}

public byte[] pass(string inn)
{
   
var algoritme = System.Security.Cryptography.SHA1.Create();
   
byte[] data, utdata;
    data
= System.Text.Encoding.ASCII.GetBytes(inn);
    utdata
= algoritme.ComputeHash(data);
   
return utdata;
}
public User loggInn(User inn)
{
   
using (var db = new DataClassesDataContext())
   
{
       
byte[] passordArray;
        passordArray
= pass(inn.password);
       
try
       
{
           
var brukere = from s in db.TUsers
                         
where s.Username == inn.username &&
                           s
.Password == passordArray
                         
select new User
                         
{
                              username
= s.Username,
                              email
= s.Email,
                              role
= s.Role,
                              lastvisit
= Convert.ToDateTime(s.Lastvisit)
                         
};
           
if (brukere.Count() == 0 || brukere == null)
           
{
               
return null;
           
}

           
User user = brukere.First();

           
char[] x = inn.username.ToCharArray();
           
int a = x.Length;
           
char[] y = user.username.ToCharArray();
           
for (int i = 0; i < x.Length; i++)
           
{
               
if (!y[i].Equals(x[i]))
                   
return null;
           
}
           
return user;
       
}
       
catch (Exception err)
       
{
           
return null;
       
}
   
}
}
}

my web.config

<?xml version="1.0"?>
<configuration>
 
<connectionStrings>
   
<add name="testdbConnectionString" connectionString="Data     Source=tcp:myhost.com;Initial Catalog=testdb;User ID=testdb_user;Password=*****"
 
providerName="System.Data.SqlClient" />
 
</connectionStrings>
 
<system.web>
   
<compilation debug="false" targetFramework="4.0">
     
<assemblies>
       
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
   
</assemblies>
 
</compilation>
 
</system.web>
</configuration>

Answers (2)