在asp.net webservice中如何使用session
原文:刘武|在asp.net webservice中如何使用session
在使用asp.net编写webservice时,默认情况下是不支持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 ......
控制网站分辨率 我们可以 用 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" /> ......
1.对IE浏览器进行设置
文件-〉页面设置-〉将里面的页眉和页脚的内容清空 就OK了
2.页面代码实现 Javascript
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><!-- & ......
在web开发中,经常要用到控件的OnClientClick与OnClick事件.
如果使用不当,经常会遇到一些意料之外的事情发生,让人摸不着头脑.下面就将我的一些小小总结道来:
首先我们要了解这两个事件:
OnClientClick是客户端事件方法.一般采用JavaScript来进行处理.也就是直接在IE端运行.一点击就运行.
OnClick事件是服务器端事件处理 ......
default.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls. ......