传输会话变量 [英] Transfer Session Variables
问题描述
我想一个VBScript会话变量传递给我的C#页面。
经研究,我发现这个网页:
I am trying to pass a vbscript session variable to my c# page. Upon research I found this page:
我不知道如何改变我的
Int32 intresortID = Convert.ToInt32(Request.QueryString["TypeID"]);
在会话变量相同的方式从上面的链接提供的code阅读(粘贴下面:)
to read in the session variable in the same manner as from the code provided in the link above(pasted below:)
<TITLE>ASPNETPage1.aspx</TITLE>
<%@ Page language="c#" %>
<script runat=server>
// We iterate through the Form collection and assign the names and values
// to ASP.NET session variables! We have another Session Variable, "DestPage"
// that tells us where to go after taking care of our business...
private void Page_Load(object sender, System.EventArgs e)
{
for(int i=0;i<Request.Form.Count;i++)
{
Session[Request.Form.GetKey(i)]=Request.Form[i].ToString();
}
Server.Transfer(Session["DestPage"].ToString(),true);
}
</script>
=============================================== ===============================
==============================================================================
<TITLE>FinalPage.aspx</TITLE>
<%@ Page language="c#" %>
<script runat=server>
// This page is just a "proof of concept page"...
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("Shared Session Variable Names/Values between Classic ASP and ASP.NET:<BR>");
for (int i = 0; i < Session.Contents.Count; i++)
{
Response.Write("Assigned to \"" +Session.Keys[i].ToString()+"\"");
Response.Write(" Value: "+ Session[i].ToString() +"<BR>");
}
}
</script>
更新:
code对于在会话变量称为C#页:
Update: Code for where session variable is called on C# page:
private void FillGrid()
{
string connStr = ConfigurationManager.ConnectionStrings["bdsConnectionString"].ConnectionString;
using (SqlConnection Con = new SqlConnection(connStr))
{
Con.Open();
Int32 intresortID = Convert.ToInt32(Request.Form["TypeID"]);
Label4.Text = Convert.ToString(intresortID);
Label4.Visible = true;
DateTime startdate;
startdate = Convert.ToDateTime(TextBox1.Text);
Int32 ed = Convert.ToInt32(TextBox2.Text);
DateTime enddate;
enddate = startdate.AddDays(ed);
string str = "SELECT TOP (100) PERCENT tblAvail.dtm as Dtm, tblResortsRooms.strRoomType as strRoomType, tblResortsRooms.strDescription as strDescription, tblAvail.intQty as intQty, tblAvail.curPrice as curPrice, tblResortsRooms.intWSCode as intWSCode FROM tblAvail INNER JOIN tblResortsRooms ON tblAvail.intResortID = tblResortsRooms.intResortID AND tblAvail.strRoomType = tblResortsRooms.strRoomType WHERE (tblResortsRooms.curRecRate > 0) AND (tblAvail.intResortID = @intResortID) and (tblAvail.dtm between @startdate and @enddate) ORDER BY tblResortsRooms.strRoomType";
SqlDataAdapter sdr = new SqlDataAdapter(str, Con);
sdr.SelectCommand.Parameters.AddWithValue("@intResortID", intresortID);
sdr.SelectCommand.Parameters.AddWithValue("@startdate", startdate);
sdr.SelectCommand.Parameters.AddWithValue("@enddate", enddate);
DataTable dt = new DataTable();
sdr.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
Button2.Visible = true;
}
}
}
有人可以请告诉我怎么样?
Can somebody please show me how?
推荐答案
底线是,在古典ASP会话变量不可用于ASP.Net(无论使用的语言)。你将需要使可用的价值的ASP.Net页面通过该被回发到ASP.Net页面查询字符串或形式。因此,建议的解决方案是通过查询字符串的ASP.Net页面传递值(这显然是在传统的ASP页面的会话变量)。然后,ASP.Net页面上检索查询字符串值,做任何你想用它。
Bottom line is that a session variable in Classical ASP is not available to ASP.Net (regardless of the language used). You will need to make that value available to the ASP.Net page via a query string or form that gets posted back to the ASP.Net page. So a suggested solution is to pass the value (which apparently is in a session variable in the classical ASP page) via a query string to the ASP.Net page. Then on the ASP.Net page retrieve the query string value and do whatever you want with it.
我希望我没有错过了点。但底线是有古典ASP和ASP.Net会话变量之间没有交互,因为它们使用完全不同的框架和引擎。
I hope I haven't missed the point. But bottom line is there is no interaction between session variables in Classical ASP and ASP.Net because they use completely different frameworks and engines.
这篇关于传输会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!