Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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
<?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>
Posted
Updated 21-Jan-12 8:44am
v2

You would advise you: never use default namespace, always put the whole file of the code like this in a certainly named name space. I refer to the source code you have shown in response to the question by Rod.

For example, create a namespace MyCompany.MyProduct.Authentication and put the code you have shown in this namespace.

When you want to use the type User in some other place, your options are:

  • Refer it in fully-qualified name: MyCompany.MyProduct.Authentication.User;
  • Use the namespace clause using MyCompany.MyProduct.Authentication;
  • Use the alias clause using User = MyCompany.MyProduct.Authentication.User;.


This syntax is a part of very basic language knowledge. You are doing a common mistake: trying to develop something advanced without sufficient knowledge of the language. Do yourself a great favor: at least read the language manual from the beginning to the end; it won't take any time which you would regret later. It will pay off pretty soon.

—SA
 
Share this answer
 
Comments
plazzasele 21-Jan-12 16:18pm    
Hi. i now have the namespace users, and have my User Class inside the namespace users. i i wrote on the top of login.aspx.cs file "using users;" but still i am getting error, i have rebuild the solution, still doesn't work. i don't thing it is just that i didn't use the namespace. beside why is this working fine locally.? i think i will try File->New->Project -> asp.net web form. maybe this way i will some better compiled files. cause the way i did is not working.
thanks for your help.
Sergey Alexandrovich Kryukov 22-Jan-12 13:00pm    
Maybe you are missing something simple. How about just reading error message thoroughly and trying to understand it? "Still does not work" is not informative.
--SA
Espen Harlinn 22-Jan-12 6:56am    
Good points :)
Sergey Alexandrovich Kryukov 22-Jan-12 12:56pm    
Thank you, Espen.
--SA
Have a look at:
Dynamic compilation in ASP.NET[^]

Personally I usually avoid dynamic compilation ...

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Jan-12 12:59pm    
Useful article, my 5, but OP is still messing up with more elementary things. Good for understanding, anyway.
--SA
Espen Harlinn 22-Jan-12 13:59pm    
Thank you, Sergey - and I suspect you're right :)
Now it is working fine. here i write what i did in case someone face the same problem.

- right click on solution and add new project-> classlibrary (name it whatevr you want).

- add the classes to the classlibrary.

- right click on the website and go to addreferences, select the classlibrary you just created.

- add using classlibrary on the top of the .cs files.

- build the solution.

- move/copy the bin folder to the root directory.

I think it is very complicated when uploading the website to server, everything works fine locally. and after much work locally things gets hard when uploading to server.!

thanks for all the help..
 
Share this answer
 
v2
Comments
Tech Code Freak 23-Jan-12 3:02am    
5up!
Great sharing the solution!
You have a class called User what is the namespace for this class?
If you include it as a using directive the error should go away.
 
Share this answer
 
Comments
plazzasele 21-Jan-12 11:38am    
Hi Permalink.
My User.cs class is in the App_Code folder. there is no namespace.!
what should i write? using "what" ?
here is my User.cs class code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class User
{
public int userId { get; set; }
public string username { get; set; }
public string email { get; set; }
public string role { get; set; }
public string password { get; set; }
public DateTime? created { get; set; }
public DateTime? lastvisit { get; set; }
public int? status { get; set; }
public string location { get; set; }
public User()
{
}
}
Sergey Alexandrovich Kryukov 21-Jan-12 14:33pm    
Too bad there is no namespace. :-(
--SA
Sergey Alexandrovich Kryukov 21-Jan-12 14:35pm    
I voted 4. OP is so weak in knowledge that extra explanation is needed. Besides, this is not the only option. There are 3 basic ways -- please see my answer.
--SA
Now it is working fine. here i write what i did in case someone face the same problem.

- right click on solution and add new project-> classlibrary (name it whatevr you want).

- add the classes to the classlibrary.

- right click on the website and go to addreferences, select the classlibrary you just created.

- add using classlibrary on the top of the .cs files.

- build the solution.

- move/copy the bin folder to the root directory.

I think it is very complicated when uploading the website to server, everything works fine locally. and after much work locally things gets hard when uploading to server.!

thanks for all the help..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900