2

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 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>
kamiran
  • 41
  • 1
  • 5

2 Answers2

1

Now it is working fine. Here I write what I did in case someone faces 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. After much work locally things gets hard when uploading to server!

David Alber
  • 17,624
  • 6
  • 65
  • 71
kamiran
  • 41
  • 1
  • 5
0

Is the User class part of the same namespace as your admin_login class? If they are not, then you need to add an additional using YourUserClassNamespace; at the top.

  • 1
    User.cs is in the App_Code folder. the App_Code folder is in the root directory the same as the admin folder is. I tried to move the login.aspx file to the same level as the App_Code folder, didn't help. – kamiran Jan 21 '12 at 14:46
  • @kamiran are you sure you've moved all of the files and folder structure? The `App_Code` folder and contents are compiled at runtime. –  Jan 21 '12 at 14:52
  • i am sure that i have moved the files, what i have read about compilation, that asp.net compiles the files that are located in the app_code folder. i have moved my files several times, trying once the deploy website, once the copy website, once using filezilla and create the files on server. no one works. :( – kamiran Jan 21 '12 at 14:57
  • @kamiran could you move your `User` class outside of the `App_Code` folder, recompile and try again? –  Jan 21 '12 at 15:15
  • i moved as you suggest, but didn't work. i clicked on Build->Build Web Site. and Build->Build Solution. – kamiran Jan 21 '12 at 15:31