【发布时间】:2015-04-30 03:56:05
【问题描述】:
namespace ASPMultilingual {
public partial class _Default : System.Web.UI.Page
{
ResourceManager rm;
CultureInfo ci;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Lang"] == null) {
Session["Lang"] ="en-US";
}
if (!IsPostBack)
{
LoadString();
}
}
private void LoadString(){
Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["Lang"].ToString());
//rm = new ResourceManager("ASPMultilingual.App_GlobalResources.Lang", Assembly.GetExecutingAssembly());
ResourceManager rm = new ResourceManager("ASPMultilingual.Lang", System.Reflection.Assembly.Load("ASPMultilingual"));
ci = Thread.CurrentThread.CurrentCulture;
btnLogIn.Text = rm.GetString("Login", ci);
}
protected void btnLogIn_Click(object sender, EventArgs e)
{
string ID = Request.Form["txtID"];
String password = Request.Form["txtPassword"];
string strConString = ConfigurationManager.ConnectionStrings["SOConnectionString"].ConnectionString;
OleDbConnection conn = new OleDbConnection(strConString);
OleDbCommand cmd = new OleDbCommand("SELECT * FROM USERMASTER", conn);
try
{
conn.Open();
OleDbDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read()) {
string testposition = dr["UserPosition"].ToString();
string dataID = dr["UserId"].ToString();
string dataPass = dr["UserPwd"].ToString();
if (dataPass == txtPassword.Text && dataID == txtID.Text)
{
Session["User_Position"] = testposition;
Response.Redirect("Default2.aspx");
}
else {
lblError.Text = "Invalid account! Please Enter again!";
}
}
}
catch (Exception ex)
{
txtID.Text = "ex";
lblError.Text = ex.ToString();
}
finally
{
conn.Close();
conn.Dispose();
}
//Response.Redirect("Default2.aspx");
//ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + ID + " " + password + "');", true);
}
protected void ddLang_SelectedIndexChanged(object sender, EventArgs e)
{
Session["Lang"] = ddLang.SelectedValue;
LoadString();
}
}
}
代码运行良好,直到我在代码之上添加命名空间,然后它抛出错误。
编译错误 说明:在编译服务此请求所需的资源期间发生错误。请查看以下具体错误详情并适当修改您的源代码。
编译器错误信息:
ASPNET:确保此代码文件中定义的类与 'inherits' 属性,并且它扩展了正确的基类(例如 页面或用户控件)。
来源错误: 第 19 行:公共部分类 _Default
【问题讨论】:
-
如果将命名空间名称更改为其他名称,例如
namespace ASPMultilingual2,是否会发生这种情况? -
它还是一样...每当我添加命名空间 xxxxx{ 时,我都会收到编译错误...实际上命名空间本身并不是自己的,我在编写所有代码后添加了它。