在asp.net webservice中如何使用session
在使用asp.net编写webservice时,默认情况下是不支持session的,但我们可以把WebMethod的EnableSession选项设为true来显式的打开它,请看以下例子:
1 新建网站WebSite
2 新建web服务WebService.asmx,它具有以下两个方法:
[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
<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
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();
lblName.Text = ws.GetName();
}
问题似乎到此结束了,按Login按钮记录用户名以后,再按GetName就可以获取到刚才输入的
相关文档:
MVC自带的ActionFilter
在Asp.Net WebForm的中要做到身份认证微软为我们提供了三种方式,其中最常用的就是我们的Form认证,需要配置相应的信息。例如下面的配置信息:
<authentication mode="Forms">
<forms loginUrl="Login.aspx" defaultUrl="Default.aspx" protection="All" />
</authenticati ......
在asp.net中导出excel 中比较通行的做法是: Response.ContentType = "application/vnd.ms-excel";
然后直接向里面扔 html 的table
但是有中文的时候 老出现乱码,有很多解决方案,但都不能通盘解决, 就是在 输出html两头输出
Response.Write("<html><head><meta http-equiv=Content-Type conte ......
看到有人提问一个空间支持多个网站的问题。
总结一下:
最好保证各个项目app_code内的文件都是一样的。
因为生成多个项目必定生成多个App_Code.dll,
由于所有dll放在同一个bin目录,所以要保证app_code内的文件一样。
发布前所有项目aspx文件的 Inherits="menulefttb" 中的名字不能相同。
将每个项目发布后生成的dll ......
asp.net在开发时,在不同的页面间跳转是我们常遇到的一件事,当一个复杂的逻辑在一个页面放不下分成二个或多个页面处理就需要在页面间跳转,用的最多还是用户的登陆吧.
ASP.NET用的最多的跳转是Response.Redirect,这个命令可以直接把请求重定向到一个相对或绝对的路径.它会把当前页面的的Http流阻断直接重定向到新的U ......
一。①:首先要有这个文件URLRewriter.dll,如果没有,赶快到网上下载一个,并将其放到下面的bin目录里面,并且将其引用添加到下面里面;
②:下面就是Web.Config文件的配置了,当然,配置过程相当简单:
1:先添加这个
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.Rew ......