ÔÚasp.net webserviceÖÐÈçºÎʹÓÃsession
ÔÎÄ£ºÁõÎä|ÔÚasp.net webserviceÖÐÈçºÎʹÓÃsession
ÔÚʹÓÃasp.net±àдwebserviceʱ£¬Ä¬ÈÏÇé¿öÏÂÊDz»Ö§³ÖsessionµÄ£¬µ«ÎÒÃÇ¿ÉÒÔ°ÑWebMethodµÄEnableSessionÑ¡ÏîÉèΪtrueÀ´ÏÔʽµÄ´ò¿ªËü£¬Çë¿´ÒÔÏÂÀý×Ó£º
1 н¨ÍøÕ¾WebSite
2 н¨web·þÎñWebService.asmx£¬Ëü¾ßÓÐÒÔÏÂÁ½¸ö·½·¨£º
C#-Code:
[WebMethod(EnableSession = true)]
public string Login(string name)
{
Context.Session["name"] = name;
return name;
}
[WebMethod(EnableSession = true)]
public string GetName()
{
if (Context.Session["name"] != null)
return Context.Session["name"].ToString();
else
return "";
}
3 Ìí¼Óasp.netÒ³ÃæSessionInWebservice.aspx
ASP.NET-Code:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:Button ID="btnLogin" runat="server"
Text="Login" OnClick="btnLogin_Click" />
</div>
<div>
<asp:Button ID="btnGetName" runat="server"
Text="GetName" OnClick="btnGetName_Click" />
<asp:Label ID="lblName" runat="server" Text="Label"></asp:Label>
</div>
</form>
SessionInWebservice.aspx.cs
C#-Code:
protected void btnLogin_Click(object sender, EventArgs e)
{
WebService ws = new WebService();
ws.Login(txtName.Text);
}
protected void btnGetName_Click(object sender, EventArgs e)
{
WebService ws = new WebService();
lblNa
Ïà¹ØÎĵµ£º
ʹÓÃASP.Net FormsģʽʵÏÖWebServiceÉí·ÝÑéÖ¤
ÔÚ°²È«ÐÔÒªÇó²»ÊǺܸߵÄASP.Net³ÌÐòÖУ¬»ùÓÚFormsµÄÉí·ÝÑéÖ¤ÊǾ³£Ê¹ÓõÄÒ»ÖÖ·½Ê½£¬¶øÈç¹ûÐèÒª¶ÔWebService½øÐÐÉí·ÝÑéÖ¤£¬×î³£ÓõĿÉÄÜÊÇ»ùÓÚSoap ±êÍ·µÄ×Ô¶¨ÒåÉí·ÝÑéÖ¤·½Ê½¡£Èç¹û¶ÔÁ½Õß×öһϱȽϵĻ°£¬ÏÔÈ»£¬»ùÓÚFormsµÄÑéÖ¤·½Ê½¸ü¼Ó·½±ãÒ×Óã¬ÄÜ·ñ½«F ......
ÔÚc# / ASP.netÖÐÎÒÃÇ¿ÉÒÔͨ¹ýʹÓÃDataTimeÕâ¸öÀàÀ´»ñÈ¡µ±Ç°µÄʱ¼ä¡£Í¨¹ýµ÷ÓÃÀàÖеĸ÷ÖÖ·½·¨ÎÒÃÇ¿ÉÒÔ»ñÈ¡²»Í¬µÄʱ¼ä£ºÈ磺ÈÕÆÚ£¨2008-09-04£©¡¢Ê±¼ä£¨12£º12£º12£©¡¢ÈÕÆÚ+ʱ¼ä£¨2008-09-04 12£º11£º10£©µÈ¡£
//»ñÈ¡ÈÕÆÚ+ʱ¼ä
DateTime.Now.ToString(); // 2008- ......
ÔÚʹÓÃAJAX½øÐгÌÐò¿ª·¢µÄʱºò£¬Ò»Ö±¶¼»áÃæ¶ÔÒ»¸ö»º´æµÄÎÊÌ⣡£¡
¼´ÊÇ£¬ÉÏ´ÎÇëÇóµÄʱºò£¬ÒòΪÄãµÄSQLÓï¾ä»òÕßÆäËûÔÒò£¬webserviceÖзµ»ØֵΪ¿Õ£¬²»ÊÇÄãÏëÒªµÄ½á¹û¼¯£¬ÔÚÄã·¢ÏÖwebserviceÖÐÓï¾äÌå³ö´íºó£¬½øÐÐÐ޸ģ¬ÖØвâÊÔ£¬ÈÔÈ»ÊÇÉϴεķµ»Ø½á¹û£¡¸Ð¾õ¾ÍÏñÄãµÄÐÞ¸ÄÍêÈ«ÎÞЧ¡£¡£
Æäʵ£¬ÕâÊÇÔÚAJAXµ ......
¿ØÖÆÍøÕ¾·Ö±æÂÊ ÎÒÃÇ¿ÉÒÔ Óà frameset
ËäÈ» asp.net²»Ö§³ÖÕâ¸öÊôÐÔ µ«Êǹ¦ÄÜÊÇ¿ÉÒÔʵÏÖµÄ
Èç £º
<frameset name="main" rows="105,*" frameborder="no" border="0" framespacing="0">
<frame src="xx.aspx" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame" /> ......
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Timers;
using System.Data;
using System.Data.SqlClient;
namespace SMS_joke
{
/// <summary>
/// Global µÄժҪ˵Ã÷¡£
/// </summary>
public class ......