是否可以使用Web服务ASP.NET C#从一个应用程序获取会话值到另一个应用程序 [英] Is it posible to get session value from one application to another application using web service ASP.NET C#

查看:83
本文介绍了是否可以使用Web服务ASP.NET C#从一个应用程序获取会话值到另一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的Web服务代码:

[WebMethod(EnableSession = true)]
public string GetStringValue(string sessionstring)
{
// return sessionstring +1;

HttpContext.Current.Session [regid] = sessionstring;

返回HttpContext.Current.Session [regid]。ToString();
}

下面是我的第一个应用程序代码,用于按钮点击将会话值传递给Web服务

protected void Button1_Click(object sender,EventArgs e)
{
localhost.WebService objserv1 = new localhost.WebService();
Session [RegId] =Mazar;
Label.Text = objserv1.GetStringValue(Session [RegId]。ToString());

}


第二个应用程序需要在页面加载时显示。

protected void Page_Load(object sender,EventArgs e)
{

// localhost.WebService objserv1 = new localhost.WebService();
// lbl_Value.Text = objserv1.GetStringValue(HttpContext.Current.Session [regid]。ToString());

}


第二个应用程序试图显示第一个应用程序会话值但没有得到任何想法。

< a href =https://i.stack.imgur.com/7gjzi.png>在此处输入图片说明

[ ^ ]



< b>我尝试了什么:



将第一个应用程序会话值获取到第二个应用程序

解决方案

< blockquote>您想通过Web方法访问什么会话?应用程序无法共享Session,因此您不太可能将其用于工作。如果用户正在浏览两个站点,那么他有两个会话,但是如果他正在浏览一个站点并且该站点向另一个站点发出呼叫,则它无法访问该站点上的该用户的会话,而是在该站点上创建新的会话站点。

Below is my Web Service code:

[WebMethod(EnableSession = true)]
public string GetStringValue(string sessionstring)
{
// return sessionstring+"1";

 HttpContext.Current.Session["regid"] = sessionstring;

 return HttpContext.Current.Session["regid"].ToString();
}

Below is my first application Code for on button click passing session value to web service

   protected void Button1_Click(object sender, EventArgs e)
{
    localhost.WebService objserv1 = new localhost.WebService();
    Session["RegId"] = "Mazar";
    Label.Text =objserv1.GetStringValue(Session["RegId"].ToString());

}


In second Application need to show on page load.

     protected void Page_Load(object sender, EventArgs e)
{

 //    localhost.WebService objserv1 = new localhost.WebService();
 //     lbl_Value.Text = objserv1.GetStringValue(HttpContext.Current.Session["regid"].ToString());

}


In Second application trying to showing first application session value but not getting any Idea.

<a href="https://i.stack.imgur.com/7gjzi.png">enter image description here

[^]

What I have tried:

Getting first application session value to second application

解决方案

What "Session" do you want to access via the web method? Applications can't share Session so it's unlikely you're going to get this to work. If a user is browsing both sites then he has two Sessions, but if he is browsing one site and that site makes a call to the other then it can't access that user's Session on that site, but instead creates a new Session on that site.


这篇关于是否可以使用Web服务ASP.NET C#从一个应用程序获取会话值到另一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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