获取会议.NET ASMX Web服务 [英] Getting session in .NET ASMX web-service

查看:170
本文介绍了获取会议.NET ASMX Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一起主持我的ASP.NET web应用程序的Web服务ASMX。现在,我需要得到用户的会话到web服务。为了测试这个我做了这个简单的方法:

I have an ASMX webservice hosted alongside my ASP.NET web app. Now, I need to get the users session into the Webservice. To test this I made this simple method:

    [WebMethod(EnableSession = true)]
    public string checkSession()
    {
        return HttpContext.Current.Session["userid"].ToString();
    }

所以,首先我登录到我的Web应用程序,然后在浏览器后藤我的web服务,并在该自动生成的测试页面点击checkSession。我有3台计算机上测试这一点。那些所有3做工精细的Web应用程序(正在创建这样的会议等),以及2返回会议的价值[将把userid]上调用的webmethod,但最后一台计算机返回对象引用不设置到例如对象的,因为会议为null。

So, first I login to my web app, then in the browser goto my webservice and click "checkSession" on that auto generated test page. I have tested this on 3 computers. All 3 of those work fine with the webapp(so the sessions are being created etc), and 2 of those return the value of Session["userid"] on invoking the webmethod, however the last computer returns "Object reference not set to an instance of an object" because Session is null.

那么,什么这些计算机之间的差异为什么我的ASP.NET应用程序得到会议的所有计算机,但web服务着?

So, whats the difference between these computers and why can my ASP.NET app get the sessions on all computers but the webservice cant?

推荐答案

SessionIDs默认情况下,存储在客户端的浏览器cookie(的会话状态概述)。所以,检查是否得到了适当的创建问题的计算机上该cookie。也许饼干是出于某种原因禁用?在这种情况下,它不会被发送的SessionID到服务器时,你打的Web服务。

SessionIDs are stored as cookies on the client's browser by default (Session State Overview). So check if that cookie is being created properly on that problem computer. Maybe cookies are disabled for some reason? In that case it would not be sending the SessionID to the server when you are hitting that web service.

这篇关于获取会议.NET ASMX Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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