Session和Application都不行
难道非要 通过链接地址 传QueryString吗
碰到类似问题的大侠请来救命

解决方案 »

  1.   

    sorry,题目产生歧义:应该是两个不同的ASP.NET项目“之间”怎么传递值
      

  2.   

    他们不能共享SESSION等东西,所以应该只能通过QueryString来传,或者通过中间介质,比如数据库...
      

  3.   

    好像除了QueryString,没有其他的简洁方法了,还有就是靠数据库,xml等辅助手段了
      

  4.   

    QueryString 这个冬冬 我在asp里
    用的很多 但在asp.net已经很少用了 看样子现在又不得不用了
      

  5.   

    querySting, database, webservice……
      

  6.   

    第一个项目中的类 a 里定义 public static int a = 1;
    在第二个项目里
    1、先在引用中引入项目a 
    2、变量b  =  a.a;可以了,记住要using项目的名字空间
      

  7.   

    在ASP与ASP.NET之间共享对话状态ASP.NET实现   在ASP.NET中每一个Web页都衍生自System.Web.UI.Page类。Page类集合了HttpSession对象的一个实例用于处理对话数据。在本例中,叫做SessionPage的自定义Page类来衍生自System.Web.UI.Page,提供了类似Page类的所有特性。唯一的区别是默认的HttpSession使用自定义的对话对象重载了(对实例变量使用new修改符,C#允许衍生的类隐藏基类的成员)。 
    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; 

      
      

  8.   


      在请求的末尾,Page类的Unload事件被启动了,一个同Unload事件一起注册的事件处理方法将串行化对话数据为二进制格式并将结果二进制数据存入SQL Server。 
    private void PersistSession(Object obj, System.EventArgs arg) 
    { sessionPersistence.SaveSession( 
      Server.UrlDecode(cookie.Value).ToLower().Trim(), dsn, Session, IsNewSession); 

    public void SaveSession(string key, string dsn,  
    mySession Session, bool IsNewSession) 

     SqlConnection conn = new SqlConnection(dsn); 
     SqlCommand SaveCmd = new SqlCommand();  
     SaveCmd.Connection = conn;  try 
     { 
      if (IsNewSession) 
       SaveCmd.CommandText = InsertStatement; 
      else 
       SaveCmd.CommandText = UpdateStatement;   SaveCmd.Parameters.Add("@ID", new Guid(key)); 
      SaveCmd.Parameters.Add("@Data", Serialize(Session)); 
      SaveCmd.Parameters.Add("@LastAccessed", DateTime.Now.ToString());   conn.Open(); 
      SaveCmd.ExecuteNonQuery(); 
     } 
     finally 
     { 
      if (conn != null) 
       conn.Close(); 
     } 

    private Byte[] Serialize(mySession Session) 

     if (Session == null) return null;  Stream stream = null; 
     Byte[] state = null;  try 
     { 
      IFormatter formatter = new BinaryFormatter(); 
      stream = new MemoryStream(); 
      formatter.Serialize(stream, Session); 
      state = new Byte[stream.Length]; 
      stream.Position = 0; 
      stream.Read(state, 0, (int)stream.Length); 
      stream.Close(); 
     } 
     finally 
     { 
      if (stream != null) 
       stream.Close(); 
     } 
     return state; 
    }     SessionPage类以及与它相关的类被封装在SessionUtility组件中。在一个新ASP.NET项目中,需要作SessionUtility组件的引用,为了与传统的ASP代码共享对话,每个页面由SessionPage代替Page类衍生出来。一旦移植完成了,新应用程序能通过说明SessionPage类中定义的对话变量切换回使用原来的HttpSession对象来显示基本的HttpSession。 
      

  9.   

    感觉楼主提的问题,其实就是一个类库的问题,假设两个.net的项目,其中一个是类库,另一个是.net的前台页面.或者像三层架构的问题,表现层,数据层,逻辑层
      

  10.   

    QueryString,还可以xml 还可以webservice
    数据量少当然使用QueryString最好,而且,asp,php等都可以互调
    xml文件存放,类似于存放到数据库了,但是它比较灵活,缺点是费操作时间了
    webservice先进多了,连win32程序都可以互相传递了,但是你要懂这个编程阿
      

  11.   

    就传 4个值 还是用QueryString 比较划算吧!
      

  12.   

    如是两个WEB项目,传值一般通过数据库为好!相信两个WEB项目中的页面如有页面间参数传递大多不是一个页面的问题,而是很多页面的问题,所以用数据库为好,当然XML文件也可以啦如是WEB项目和类库项目之间传递参数那就简单了,用类库的方法参数传递即可!
      

  13.   

    坚决支持XML方式解决,或是利用 INI 解决。
      

  14.   

    可以通过 QueryString ,数据库等解决
      

  15.   

    两个项目都把session的mode改成“sqlserver”,从而把会话保存到指定的sqlserver数据库中,还有一个方法就是mode改成stateserver,把会话保存到指定的服务器的asp.net state 服务中