由于以前系统一直用的ASP开发的代码,现在想转向ASP.NET,而以前的代码不可能都重写,造成了ASP和ASP.NET共存的现象.
我发现ASP.NET要读取ASP中的session是件很麻烦的事情,各位大哥有没有什么好的或者通用的解决方法,谢谢了.
此外,我还想问一下,系统中同时存在ASP和ASP.NET两种代码还有没有别的什么问题,请各位高手指点一下.
说明一下,小弟是初学者,以前是做嵌入式开发的,转行做这个才1个月时间,大家多多关照哦,谢谢.
我发现ASP.NET要读取ASP中的session是件很麻烦的事情,各位大哥有没有什么好的或者通用的解决方法,谢谢了.
此外,我还想问一下,系统中同时存在ASP和ASP.NET两种代码还有没有别的什么问题,请各位高手指点一下.
说明一下,小弟是初学者,以前是做嵌入式开发的,转行做这个才1个月时间,大家多多关照哦,谢谢.
解决方案 »
- 有了 ASP.NET 3.5 的 System.Web.Routing, 为什么还要 URL Rewrite Module
- 控制线程启动
- 图片显示问题
- 怎么才能把Hashtable中的键值对,对应赋给类对象的属性中去??
- 对象集合绑定到datagrid的问题。来的有分。请高手给个意见或是方案。。谢谢啦。
- 在Image控件中如何显示SQL Server数据库中的图片字段?
- 按了IE窗口右上角的红叉后,怎么清除掉用户信息?
- 帮我解决一个小问题,file field的路径问题,帮帮忙~~~~~~~~~~~~~很急急急急急急急急急急急急急急急急
- 有没有其它比较好用的DataGrid控件?
- 在一个论坛里,管理怎样使另一在线用户的session失效?
- acrobat进程的问题
- 散分,ZForums V2.0 终于发布。另外,提供FTB1.6.3修改后的源代码
可以同时存在ASP和ASP.NET的。
我碰到时是用第一种传参的方法了.就是从asp到aspx或 aspx到asp都经过处理传参你可以试试这个用隐藏表单的方式来将asp.net中的session传入asp中:
http://www.eggheadcafe.com/articles/20021207.asp另外还有一些其它方法:
http://www.eggheadcafe.com/articles/20041017.asp另外.MSDN上有一种方法 :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/converttoaspnet.asp
public class SessionPage : System.Web.UI.Page
{
...
public new mySession Session = null;
...
} 自定义的对话类使用HybridDictionary对象来相应保存内存中的对话状态(HybridDictionary可用于处理任意数量的对话元素)。为了与传统的ASP通用,该自定义对话对象将限制对话数据类型为字符串型(默认的HttpSession允许对话保存任意类型的数据,不能与传统的ASP通用)。
[Serializable]
public class mySession
{
private HybridDictionary dic = new HybridDictionary(); public mySession()
{
} public string this [string name]
{
get
{
return (string)dic[name.ToLower()];
}
set
{
dic[name.ToLower()] = value;
}
}
}
Page类为定制暴露了不同的事件和方法。特别是OnInit方法用于设置Page对象的初始化状态。如果请求不包含名为mySession的Cookie,将为请求者产生一个新的mySession Cookie。另外,对话数据将使用自定义数据访问对象SessionPersistence从SQL Server中检索出来。DSN和SessionExpiration的值从web.config中检索。
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
cookie = this.Request.Cookies[sessionPersistence.SessionID]; if (cookie == null)
{
Session = new mySession();
CreateNewSessionCookie();
IsNewSession = true;
}
else
Session = sessionPersistence.LoadSession(
Server.UrlDecode(cookie.Value).ToLower().Trim(),
dsn,
SessionExpiration
); this.Unload += new EventHandler(this.PersistSession);
}
private void CreateNewSessionCookie()
{
cookie = new HttpCookie(sessionPersistence.SessionID,
sessionPersistence.GenerateKey());
this.Response.Cookies.Add(cookie);
}
SessionPersistence类使用微软.NET框架组件的BinaryFormatter来串行化和并行化对话状态为二进制格式以提供最佳性能。结果的二进制对话数据接着作为图象字段类型被存入SQL Server。
public mySession LoadSession(string key, string dsn,
int SessionExpiration)
{
SqlConnection conn = new SqlConnection(dsn);
SqlCommand LoadCmd = new SqlCommand();
LoadCmd.CommandText = command;
LoadCmd.Connection = conn;
SqlDataReader reader = null;
mySession Session = null; try
{
LoadCmd.Parameters.Add("@ID", new Guid(key));
conn.Open();
reader = LoadCmd.ExecuteReader();
if (reader.Read())
{
DateTime LastAccessed =reader.GetDateTime(1).AddMinutes(SessionExpiration);
if (LastAccessed >= DateTime.Now)
Session = Deserialize((Byte[])reader["Data"]);
}
}
finally
{
if (reader != null)
reader.Close();
if (conn != null)
conn.Close();
} return Session;
}
private mySession Deserialize(Byte[] state)
{
if (state == null) return null; mySession Session = null;
Stream stream = null; try
{
stream = new MemoryStream();
stream.Write(state, 0, state.Length);
stream.Position = 0;
IFormatter formatter = new BinaryFormatter();
Session = (mySession)formatter.Deserialize(stream);
}
finally
{
if (stream != null)
stream.Close();
}
return Session;
}
在请求的末尾,Page类的Unload事件被启动了,一个同Unload事件一起注册的事件处理方法将串行化对话数据为二进制格式并将结果二进制数据存入SQL Server。