I have an ASP.Net web apps application. Where I am using session to save a data. The application calls an external application where user can select a value and the selected value is stored in an external store and it returns a key to a return site which is an End.aspx page on our application.
I need to identify that I have received a key and then get the details and update the controls with value on the calling page. Since the End.aspx is independent page to let the calling page know that a key has been received I am saving the key in Session.
On the calling page.aspx, I have a timer pool that will call an ajax post to a WebMethod where I check if the session has the value to start processing, and then return true for the timer to stop.
All this works as expected when the site is hosted on IIS as Application on the 'Default Web Site' and the external site is also hosted in the same 'Defacult web site', but when I host this site directly as a Website on IIS and the external website is still on 'Default web site', now when the external website calls the return URL to end.aspx, it creates a new session id store, hence the WebMethod that is on the calling page gets a null value.
Is there a way to use the same session even if the two sites are hosted in different domains like in e.g., above, please can you suggest if any better approach possible.
I am storing the session in SQL.
Below is the code I am using. have two different sites. e.g. Site1 and Site2. Site1 is hosted as website on IIS (http://site1) and site2 is hosted as application on 'Default web site' (http://myvm/site2)
In Site 1 I have a page customerpage.aspx which I open it as a popup form bookpage.aspx. In the Customerpage.aspx I open the site2 (http://myvm/site2/customerfinder.aspx?returnurl=http://site1/end.aspx).
Now from the site2 when a customer is selected it will then call the return URL. This invokes http://site1/end.aspx. In here I am adding the values sent by site2 to session, but in this case, it is creating a new session id.
Now I have the ajax call in customerpage.aspx which calls the WebMethod to keep checking if the session has the given value but since the session id on the customerpage.aspx is different it gets a null value.
In End.Aspx.cs that will be called by the external application as return URL
public class End : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
HttpContext.Current.Session["closed"] = true;
}
}
In the Customerpage.aspx.cs
public partial class CustomerPagepopup : System.Web.UI.Page
{
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod(EnableSession = true)]
public static bool CheckClosed()
{
bool closed = false;
if (HttpContext.Current.Session["closed"] != null)
{
HttpContext.Current.Session["closed"] = null;
return true;
}
return closed;
}
}
here is the JS that calls the WebMethod from the customerpage.aspx
function GetIfClosed() {
$.ajax({
type: "POST",
url: '<%= ResolveUrl("callingpage.aspx/CheckClosed") %>',
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// Evaulate result..
var process = msg.d
if (process) {
// destroy the timer to stop polling for progress
clearTimeout(timer);
$("#cboxClose").click();
// Do your final message to the user here.
} else {
// poll timer for another trip
TimerPoll();
}
}
});
}