类型或命名空间名称'用户'找不到(是否缺少using指令或程序集引用?) [英] The type or namespace name 'User' could not be found (are you missing a using directive or an assembly reference?)

查看:861
本文介绍了类型或命名空间名称'用户'找不到(是否缺少using指令或程序集引用?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的文件 - >新建 - >网站一个网站。
我试图去mydomain.com/piro/admin/login.aspx~~V
我创建了一个名为User.cs类,这个类是在APP_ code文件夹中。当我在本地运行这个网站,一切正常,但是当我将文件移动到服务器我得到的用户类型的错误。我试图部署我的网站,复制我的网站,以创建FTP网站上新的,但实在不行,我已经寻找一个解决方案,但无法找到我的问题任何回答。任何一个可以请帮助..!
这里是我的code。

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
使用System.Data.SqlClient的;
使用System.Data这;公共部分类admin_login:System.Web.UI.Page
{
 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    Label1.Text =;
}
保护无效的button1_Click(对象发件人,EventArgs的发送)
{
    用户的用户=新用户();
    user.username = txtUsername.Text;
    user.password的= txtPassword.Text;    用户登录= loggInn(用户);
    如果(登录== NULL)
    {
        Label1.Text =用户名或密码错误;
    }
    其他
    {
        会话[username的] = user.username;
        会话[lastvisit] = login.lastvisit;
        会话[systemUser] = login.role;
        //会话[罗尔] = godkjent.rolle;
        的Response.Redirect(Default.aspx的);
    }
    //字符串loggInn = checkUserLinq(用户);    //字符串检查= checkUser(用户);
}公众的byte []通(串店)
{
    变种algoritme = System.Security.Cryptography.SHA1.Create();
    字节[]数据,utdata;
    数据= System.Text.Encoding.ASCII.GetBytes(INN);
    utdata = algoritme.ComputeHash(数据);
    返回utdata;
}
公共用户loggInn(用户INN)
{
    使用(VAR DB =新DataClassesDataContext())
    {
        字节[] passordArray;
        passordArray =通(inn.password);
        尝试
        {
            在db.TUsers VAR brukere =从s
                          其中,s.Username == inn.username&放大器;&安培;
                           s.Password == passordArray
                          选择新用户
                          {
                              用户名= s.Username,
                              电子邮件= s.Email,
                              角色= s.Role,
                              lastvisit = Convert.ToDateTime(s.Lastvisit)
                          };
            如果(brukere.Count()== 0 || brukere == NULL)
            {
                返回null;
            }            用户的用户= brukere.First();            的char [] X = inn.username.ToCharArray();
            INT A = x.Length;
            的char [] Y = user.username.ToCharArray();
            的for(int i = 0; I< x.Length;我++)
            {
                如果(!Y [I] .Equals(X [I]))
                    返回null;
            }
            返回用户;
        }
        赶上(例外错误)
        {
            返回null;
        }
    }
}
}

我的web.config

 <?XML版本=1.0&GT?;
<结构>
  <&是connectionStrings GT;
    <添加名称=testdbConnectionString的connectionString =数据源= TCP:myhost.com;初始目录= TESTDB;用户ID = testdb_user;密码= *****
  的providerName =System.Data.SqlClient的/>
  < /&是connectionStrings GT;
  <&的System.Web GT;
    <编译调试=假targetFramework =4.0>
      <&集会GT;
        <添加组件=System.Data.Linq程序,版本= 4.0.0.0,文化=中性公钥= B77A5C561934E089/>
   < /组件>
  < /编译>
  < /system.web>
< /结构>


解决方案

现在它工作正常。在这里,我写我所做,以防有人面临着同样的问题。


  • 右键单击解决方案,并添加新的项目 - > classlibrary(命名为您希望whatevr)。

  • 的类添加到classlibrary。

  • 右键单击该网站上,去addreferences,选择刚刚创建的classlibrary。

  • 添加使用classlibrary上的.cs文件的顶部。

  • 生成解决方案。

  • 将/ bin文件夹复制到根目录。

我想上传到网站服务器时,这是非常复杂的;一切工作在本地的罚款。经过大量的工作在本地的东西上传到服务器时变得很难!

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>

解决方案

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!

这篇关于类型或命名空间名称'用户'找不到(是否缺少using指令或程序集引用?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆