http://code365.com/tech/1/15/Article/2379.Asp你自己看看吧
解决方案 »
- 简单问题,如何给GUID赋值?
- 根据IP地址快速解析主机名?
- 关于绑定的问题,求解.datasource和fill有什么不同?
- <%# DataBinder.Eval(Container.DataItem,"字段名").ToString()%>
- Web 下如何让放在Panel上的控件能自由的移动排版??
- C# Windows 编程中,如何写一个自定义控件????
- 高手帮个忙啊,VS环境下如何获得随即数?
- c# 使用gdi+绘制跑马灯长时间运行问题
- wcf的service客户端代理类用注入实例化是否有意义?
- 关于bin和obj文件夹。
- 有什么好的换肤控件推荐,类似于SkinMagicLib?
- 关于控件和窗体之间的事件处理
root
{
主要的界面都在这里
Default.aspx等等..
Controls{控件存放地,登录控件,页头,页尾等}
Process{Session控制处,可以存储,获得指定的Session}
}//这里是登录控件处,查看是否验证用户,验证的话就显示用户名if(Request.IsAuthenticated!=true)
{
SpanLogin.Visible = true;
SpanLogOut.Visible = false;
}
else
{
SpanLogin.Visible = false;
SpanLogOut.Visible = true;
Process.AccountController accountController = new Process.AccountController();
AccountInfo myAccount = accountController.GetAccountInfo(false);
this.LabelUserName.Text = myAccount.UserName.Trim();
}
//Session控制登录处
public bool ProcessLogin(string userName, string password)
{
Account account = new Account();
AccountInfo myAccountInfo = account.SignIn(userName, password);
if (myAccountInfo != null)
{
HttpContext.Current.Session[ACCOUNT_KEY] = myAccountInfo;
return true;//这里确实有Session了
}
return false;
}
//获得保存在Session里的用户信息,这里就没用了
public AccountInfo GetAccountInfo(bool required)
{
AccountInfo myAccount = (AccountInfo)HttpContext.Current.Session[ACCOUNT_KEY];
return myAccount;//返回为null
}
进入主页面后,通过菜单进入Login.aspx页面,在那里登录,成功后在该页面的显示用户信息就不正常。Session已经重起了。
private void BtnLogin_Click(object sender, System.EventArgs e)
{
this.LabelErrorMsg.Visible=false;
if (Page.IsValid)
{
// Get the user info from the text boxes
string username = this.txtUserName.Text;
string password = this.txtUserPassword.Text; // Hand off to the account controller to control the naviagtion
Process.AccountController accountController = new Process.AccountController(); if (!accountController.ProcessLogin(username, password))
{ // If we fail to login let the user know
LabelErrorMsg.Text = "登录失败!请重新登录!";
LabelErrorMsg.Visible = true;
}
}
} private void BtnRegistUser_Click(object sender, System.EventArgs e)
{
Process.AccountController accountController = new Process.AccountController(); // Retrieve the account information from the account controller
AccountInfo myAccount = accountController.GetAccountInfo(false);//这里返回的就是null值 LabelErrorMsg.Text = myAccount.UserName;
LabelErrorMsg.Visible=true;
}
1.启动服务: ASP.NET State Service
2.设置Web.Config:
<sessionState mode="StateServer" ....
那个方法我试过了,不行的!