如何使用会话变量将值从aspx页面传递到html页面? [英] How to pass value from aspx page to html page using session variable ?

查看:116
本文介绍了如何使用会话变量将值从aspx页面传递到html页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个问题,我需要使用session将值从aspx页传递到html页面。我不想使用url查询字符串传递值,



例如,我有login.aspx页面和Welcome.html,在这个如果使用登录我需要将用户名传递给欢迎页面。当登录时间可以存储在会话或公共变量并在欢迎页面中检索并显示在欢迎页面输入框中。



注意:我不想要像Welcome.html那样的url查询字符串?用户名= aaaa



请尽快回复



问候

Aravind

Hi
I have one problem,i need to pass value from aspx page to html page using session.I don't want pass value using url query string,

For example,i have login.aspx page and Welcome.html,in this if use login i need to pass username to welcome page.When login time can store in session or public variable and in welcome page retrieve and show in welcome page input box.

Note:I don't want url query string like Welcome.html?Username=aaaa

Pls reply asap

Regards
Aravind

推荐答案

希望在html页面中获得会话变量的值 [ ^ ]

Want to get value of session variable in html page[^]
引用:

由于HTML页面按原样提供,服务器上没有运行代码,因此无法访问会话。您需要将其设置为ASP.NET页面,或PHP页面,或其他页面正在运行的任何其他框架。然后您可以访问会话,与其他页面相同。

As a HTML page is served as is, with no code running on the server, it cannot access the session. You'd need to make it an ASP.NET page, or a PHP page, or whatever other framework your other pages are running in. Then you can access the Session, the same as with your other pages.


将要传递的值添加到cookie中的HTML页面并使用客户端脚本访问它
Add the value you want to pass to the HTML page in cookies and access it using client side script


这是使用ASP向响应中添加cookie的方法.NET C#



This is how you add cookies to response using ASP.NET C#

HttpCookie myCookie = new HttpCookie("UserSettings");
myCookie["Font"] = "Arial";
myCookie["Color"] = "Blue";
myCookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(myCookie);





并使用以下Javascript读取cookie



And read the cookie using Javascript as below

    var ca = document.cookie.split(';');
    //Access value of font and color by using ca[0] and ca[1] respectively
}


这篇关于如何使用会话变量将值从aspx页面传递到html页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆