locked
Access session after calling ASHX handler from WPF application RRS feed

  • Question

  • Hi Everyone,

    I am a newbee for wpf applcation. i have wrote the code to call asp.net ashx handler which work perfectly but i am facing a problem of access the session which is already created on load of the aspx page.

    the below code is the thing i wrote

    ASPX
    
      <form id="form1" runat="server">
        <div>
        <asp:Button ID="btnSample" runat="server" onclick="btnSample_Click" Text="Click Me" />
            <iframe width="900px" runat="server" id="iFraSigner1" height="125" src="../ClientBin/WpfBrowserApplicationDSC.xbap">
            </iframe>
        </div>
        </form>
    
    ASPX.CS
    public partial class Test : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    Temp objTemp = new Temp();
                    objTemp.No = 1;
                    objTemp.Name = "RAM";
                    Session["test"] = objTemp;
                }
            }
    
            protected void btnSample_Click(object sender, EventArgs e)
            {
                 
                iFraSigner1.Attributes["src"] = "../ClientBin/WpfBrowserApplicationDSC.xbap?id=ram.pdf";
    
                ClientScript.RegisterStartupScript((Type)GetType(), "PopupScript", "<script language='javascript'>document.getElementById('iFraSigner1').src=document.getElementById('iFraSigner1').src;      </script>");
    
            }
        }
        public class Temp
        {
            public int No { get; set; }
            public String Name { get; set; }
        }
    
    XAML.CS
            private void btnDigitalSigner_Click(object sender, RoutedEventArgs e)
            { 
               String queryString = System.Windows.Interop.BrowserInteropHelper.Source.Query;
    
               if (queryString != null && queryString.Length != 0)
               {
                   queryString = queryString.Remove(0, 4);
                   byte[] objByte = SignHashed(queryString);
                   if (objByte.Count() > 0)
                   {
                       UploadFile(new MemoryStream(objByte));
                   }
                   lblError.Content = "Letter is Digtially Signed and Saved.";
               }
               else
               {
                   lblError.Content = "Letter is Not previewed.";
               } 
            }
    
          
            private void UploadFile(Stream data)
            {
                //string url = string.Format("_http://{0}:{1}/DSCLetterHandler.ashx", BrowserInteropHelper.Source.Host, BrowserInteropHelper.Source.Port);
                string url = "http://localhost:57033/DSCLetter.ashx";
                UriBuilder ub = new UriBuilder(url); 
                WebClient c = new WebClient();
                c.OpenWriteCompleted += (sender, e) =>
                {
                    PushData(data, e.Result);
                    e.Result.Close();
                    data.Close();
                };
                c.OpenWriteAsync(ub.Uri); 
            } 
            private void PushData(Stream input, Stream output)
            {
                byte[] buffer = new byte[input.Length];
                int bytesRead;
    
                while ((bytesRead = input.Read(buffer, 0, buffer.Length)) != 0)
                {
                    output.Write(buffer, 0, bytesRead);
                } 
            }
    
    DSCLetter.ashx
    
    /// <summary>
        /// Summary description for DSCLetter
        /// </summary>
        public class DSCLetter : IHttpHandler, IRequiresSessionState
        {
    
            public void ProcessRequest(HttpContext context)
            { 
                //System.Web.HttpContext.Current.Session["LETTER"] = context.Request.InputStream;
                Temp objString = (Temp)System.Web.HttpContext.Current.Session["test"];
    
            } 
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    

    But always the objString is null when we try to access. Kindly help me.

     

     

     

     

    Thursday, October 13, 2011 9:00 AM

Answers

  • You can use Cache or application to store any data shared between all web users. You can use Guid.NewGuid() to get some unique key for WPF, and send them to aspx page and ashx handler to get record from Application or Cache

    Application is same as Session but shared between all users. Cache is same as Application but you can set some expiration for data.

    • Edited by Andrey Danilchenko Thursday, October 13, 2011 5:36 PM
    • Proposed as answer by Jie Bao Sunday, October 16, 2011 5:32 PM
    • Marked as answer by Jie Bao Monday, October 24, 2011 5:53 AM
    Thursday, October 13, 2011 5:34 PM

All replies

  • You can use Cache or application to store any data shared between all web users. You can use Guid.NewGuid() to get some unique key for WPF, and send them to aspx page and ashx handler to get record from Application or Cache

    Application is same as Session but shared between all users. Cache is same as Application but you can set some expiration for data.

    • Edited by Andrey Danilchenko Thursday, October 13, 2011 5:36 PM
    • Proposed as answer by Jie Bao Sunday, October 16, 2011 5:32 PM
    • Marked as answer by Jie Bao Monday, October 24, 2011 5:53 AM
    Thursday, October 13, 2011 5:34 PM
  • If you need to use session, you need to access page which hosted your wpf or silverlight application. You need to get session id from here. Then you can get session by this id. Id is stored in browser cookies
    Thursday, October 13, 2011 5:39 PM
  • You can use Cache or application to store any data shared between all web users. You can use Guid.NewGuid() to get some unique key for WPF, and send them to aspx page and ashx handler to get record from Application or Cache

    Application is same as Session but shared between all users. Cache is same as Application but you can set some expiration for data.

    Really sorry for not responding for the past one month. the answer was perfect which solve my problem perfectly.
    Thursday, November 3, 2011 5:37 AM