我在登陆时候已经这样做了,Session["username"] = username;
但是我的系统中有一个asp的页面,现在我必须在这个页面中得到username ,
我是这样做的:
sqlString = "select * from notes where UserId ='"&session("username")&"'"
但是无法得到数据,所以我就尝试这样:
session("username")="liwei"
sqlString = "select * from notes where UserId ='"&session("username")&"'"
我在前面直接将名字放入Session中,就读了出来,不知道怎么回事?难道aspx中放入的Session,在
asp的页面中却读不出来?帮忙,在线等!谢谢!
但是我的系统中有一个asp的页面,现在我必须在这个页面中得到username ,
我是这样做的:
sqlString = "select * from notes where UserId ='"&session("username")&"'"
但是无法得到数据,所以我就尝试这样:
session("username")="liwei"
sqlString = "select * from notes where UserId ='"&session("username")&"'"
我在前面直接将名字放入Session中,就读了出来,不知道怎么回事?难道aspx中放入的Session,在
asp的页面中却读不出来?帮忙,在线等!谢谢!
解决方案 »
- System.Data.SqlClient.SqlException (0x80131904): 对象名 '@tablename' 无效。
- Calender控件问题
- jmail 报错 找不到指定的模块。
- |M| 200分:求SQL查询语句:多表汇总 谢谢
- 兄弟姐妹们,谁能教我怎么样写一个像迅雷一样的电影下载系统啊!跪求!!!!![em:9:]
- 关于window.open的问题,比较急,
- 菜鸟问题~ 如何控制IE窗口的问题
- 我用response.write("1+2的值为3"),结果会是什么呢??肯定会有人错
- 还是想问一个幼稚的问题:第三方控件安装后,如果到时候上传到服务器,服务器那边没有安装控件,会否正常运行?
- 关于刷新问题
- 如何将DataSet.Table["Table1"]中的数据存进DataSet.Table["Table2"]中?
- 一个比较难的问题:pubfunction aa=new pubfunction();如果aa不用了,如何释放资源。
如果是,恭喜你,Session失效了,
There has also been considerable newsgroup discussion about this issue, most everyone saying it "can't be done". You can follow some of the original threads HERE. If you read through these (and there are many others - its a very common question!) you will see that 9 out of 10 respondents, including the MVP's and MS gurus, are all saying "it can't be done...".
I eventually gave up as I really didn't need to do it at the time, but recently Robbe Morris, my erstwhile Eggheadcafe.com developer partner, and I decided we were going to make some additions to the site in ASP.NET. The problem was, most of our site is still written in Classic ASP. We've spent a lot of time optimizing it, it scales great, and we have no particular inclination to "prove to the world" that we can rewrite the whole site in ASP.NET. Newer stuff of course, we almost always write in ASP.NET because we love it.
So unfortunately (or fortunately, as the case may be) I had to revisit this "impossible problem". Fact is, the answer is so simple if you just sit down and think it through!
The easiest way to explain this is to simply post the code, so here goes. These pages appear in the same order in which they are used, so just read through the code below:
<TITLE>ASPPage1.asp</TITLE><%' This is the page where we just set some Classic ASP Session Variables' ASPPage2.asp is where the work is done.Session("username")="joeblow"session("email")="[email protected]"Session("userid")=2Session("DestPage")="Finalpage.aspx"Server.Transfer("ASPPage2.asp")%> ==========================================================================<TITLE>ASPPage2.asp</TITLE><%' We graf all the session variable names/values and stick them in a form' and then we submit the form to our receiving ASP.NET page (ASPNETPage1.aspx)...Response.Write("<form name=t id=t action=ASPNETPage1.aspx method=post >")For each Item in Session.ContentsResponse.Write("<input type=hidden name=" & Item)Response.Write( " value=" & Session.Contents(item) & " >")nextResponse.Write("</FORM>")Response.Write("<script>t.submit();</script>")%>============================================================================<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>
As can be easily seen, all we need to do is grab the Classic ASP Session variables, contruct a dynamic form in a new Classic ASP page consisting of their names and values as hidden form fields, and submit it to our receiving ASP.NET page where we simply iterate the Form NameValueCollection , sticking the names and values into ASP.NET variables! You want to use Server.Transfer because its much more efficient than making another browser trip with Response.Redirect.
To make it more extensible, one of the Session variables, "DestPage" is used to tell us "where to go" when we're done with our little conversion. You would probably want to set this in the page that makes the call to the utility page, ASPPage2.asp. In this manner, you can use the two pages ASPPage2.asp and ASPNETPage1.aspx in almost any situation. And don't forget - you can reverse the process just as easily to transfer ASP.NET Session variables back to Classic ASP! As a last note, one reader commented about how you would handle the fact that somebody was in the ASP.NET portion of your site and meanwhile their Classic ASP session had expired. No problem! Since you brought all your session "baggage" with you when you came over, all of it (including any new stuff) would simply come back with you into a brand new ASP Session.