WebClient Lost my Session
Posted
by
kamiar3001
on Stack Overflow
See other posts from Stack Overflow
or by kamiar3001
Published on 2010-12-27T06:49:14Z
Indexed on
2010/12/27
6:53 UTC
Read the original article
Hit count: 298
Hi folks
I have a problem first of all look at my web service method :
[WebMethod(), ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetPageContent(string VirtualPath)
{
WebClient client = new WebClient();
string content=string.Empty;
client.Encoding = System.Text.Encoding.UTF8;
try
{
if (VirtualPath.IndexOf("______") > 0)
content = client.DownloadString(HttpContext.Current.Request.UrlReferrer.AbsoluteUri.Replace("Main.aspx", VirtualPath.Replace("__", ".")));
else content = client.DownloadString(HttpContext.Current.Request.UrlReferrer.AbsoluteUri.Replace("Main.aspx", VirtualPath));
}
catch { content = "Not Found"; }
return content;
}
As you can see my web service method read and buffer page from it's localhost it works and I use it to add some ajax functionality to my web site it works fine but my problem is Client.DownloadString(..) lost all session because my sessions are all null which are related to this page for more description. at page-load in the page which I want to load from my web service I set session :
HttpContext.Current.Session[E_ShopData.Constants.SessionKey_ItemList] = result;
but when I click a button in the page this session is null I mean it can't transfer session.
How I can solve this problem ? my web service is handled by some jquery code like following :
$.ajax({ type: "Post",
url: "Services/NewE_ShopServices.asmx" + "/" + "GetPageContent",
data: "{" + "VirtualPath" + ":" + mp + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
complete: hideBlocker,
success: LoadAjaxSucceeded,
async: true,
cache: false,
error: AjaxFailed
});
© Stack Overflow or respective owner