Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simplicio Jison Jr. 24 posts 44 karma points
    Mar 11, 2010 @ 08:19
    Simplicio Jison Jr.
    0

    PageMethods on System.Web.UI.Page

    Hi Guys,

    This is reference to same implementation in http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx.

    Basically I have issue working on PageMethods in User Controls since I assume that PageMethods are only available on System.Web.UI.Page Objects.

    My question is how can we add methods on the umbraco Page object? or perhaps any solution that I can use PageMethods on Umbraco since in umbraco I assume we can only use UserControl as Server object.

    In whole picture I will be using this PageMethods on Silverlights that I bind on umbraco. But I Have Issue doing it on Usercontrol so I just add normal ASP.NET Page and add it on umbraco. But this is not the best solutions since I may bypass umbraco permission , etc.

     

    I hope you guys have suggestions for this.

     

    Regards,

    Simplicio

     

     

     

     

  • Max Edwards 26 posts 50 karma points
    Mar 11, 2010 @ 10:21
    Max Edwards
    1

    The link you posted doesn't work for me but if I am understanding you correctly you are looking for a way to run server side code from the client such as ajax or from silverlight using PageMethods.

    You should take a look at /base: http://our.umbraco.org/wiki/reference/umbraco-base

    It provides a super simple way of accessing server side code from the client.

    Max

     


  • Aaron Powell 1708 posts 3046 karma points c-trib
    Mar 11, 2010 @ 11:10
    Aaron Powell
    0

    I never managed to get page methods working in Umbraco, instead I prefer to just use ASMX and set them up to be ScriptMethods. 

    You can add your own custom stuff to the base Page if you inherit from it and then modify the default.aspx to inherit your custom page. I don't know if there's other problems that that will cause bit it'd be where you start.

  • Simplicio Jison Jr. 24 posts 44 karma points
    Mar 12, 2010 @ 03:06
    Simplicio Jison Jr.
    0

    Hi Slace & Max,

    Thank you for your reply . Im not so sure if we can call authentication on the current settion when using Web Service, I assume its on an isolated session. But please correct me if I am mistaken.

    I have this silverlight app that need authentication from Umbraco members. So to invoke this I have to call client Script  loginUser(username, password)  then pass it to page methods userlogin(string userName, string password).

     

    To my understanding Im not so sure if I can Authenticate umbraco members via webservice? if that so perhaps I can use base or ASMX.

    Thanks you guys in advance for the big help,

     

     

    SILVERLIGHT CODE

        private void OKButton_Click(object sender, RoutedEventArgs e)

            {

                HtmlPage.Window.Invoke("loginUser", txtUserName.Text,  txtPassword.Password.ToString());

                this.DialogResult = true;

            }

     

     

    ASPX PAGE

     

    CLIENT SCRIPT

     

     <script type="text/javascript">

             function loginUser(username, password) {          

                 PageMethods.userlogin(username, password, OnSucceeded);             

             }

             function OnSucceeded(result, userContext, methodName) {

                 if (result) {

                     window.location = " <% =Request.Url.AbsoluteUri.ToString()  %>";
                              }

                 else {

                    window.location = " <% =Request.Url.AbsoluteUri.ToString()  %>";
                 }   }

        </script>

     

    CODE BEHIND

     

     [WebMethod, ScriptMethod]

            public static bool userlogin(string userName, string password)

            {

                Member m = Member.GetMemberFromLoginNameAndPassword(userName, password);           

                if (m != null)
                {                

                    Member.AddMemberToCache(m,true, new TimeSpan(2, 0, 0));               

                    return true;
                }

                return false;        

     

            }

     

     

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Mar 14, 2010 @ 08:59
    Aaron Powell
    0

    I suggest you actually learn a bit more about AJAX and how MS AJAX works in regards to PageMethods and ASMX. 

    A PageMethod is nothing more than a static method embedded in a class which inherits from System.Web.UI.Page and when you set it to static and have the ScriptMethod attribute.
    When you include a ScriptManager the page response is processed and the ScriptMethods are detected, then JavaScript in injected (although with a client proxy method) to allow it to be invoked via JavaScript.

    A PageMethod is actually called via 'MyPage.aspx/MyPageMethod'.

    You can invoke this yourself with a framework like jQuery, but since it's just a URL you can swap it out into something like an ASMX or a WCF JSON service.

    Here's a good post which covers how to use jQuery to call an ASMX: http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/

    Also, keep in mind that a PageMethod doesn't actually have page scope. You can't (from the server) interact with controls, Session, Request, Response, etc all have to be accessed via the static property on HttpContext. And so on. All of this is also the same in an ASMX.

  • Simplicio Jison Jr. 24 posts 44 karma points
    Mar 14, 2010 @ 10:14
    Simplicio Jison Jr.
    0

    Hi slace ,

    You are right with

    so, keep in mind that a PageMethod doesn't actually have page scope. You can't (from the server) interact with controls, Session, Request, Response, etc all have to be accessed via the static property on HttpContext. And so on. All of this is also the same in an ASMX.

     

    But it affect the Current Session specialy user identify on the sesssion. Do you think we can do this on ASMX? or WCF?

    Notice

           Member m = Member.GetMemberFromLoginNameAndPassword(userName, password);           

                if (m != null)
                {                

                    Member.AddMemberToCache(m,true, new TimeSpan(2, 0, 0));               

                    return true;
                }

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Mar 15, 2010 @ 12:43
    Aaron Powell
    0

    Well first off you shouldn't be interacting with the Membership API in Umbraco directly, unless you're working on a v3.0.x site as Umbraco 4 moved to the ASP.NET Membership Provider model - http://our.umbraco.org/wiki/how-tos/membership-providers

    And session scope for a person on your website is maintained by a cookie which is sent to/ from the server, which is why when you use Session as a storage module it exists for just that user and only while they have their browser open to your site (and the session timeout hasn't been hit of course).

    (Although using Session for storing data is a really bad idea anyway, but that's another topic all together)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 15, 2010 @ 15:04
    Jeroen Breuer
    0

    This is a bit offtopic, but I've read the wiki about the membership provider, and it seems there are still some limitations. How can you acces the membertype of a member using the ASP.NET Membership Provider model and how can I access extra properties I added to a membertype? Currently I still do this by directly interacting with the Membership API of Umbraco. I've created a topic with problems I ran into using the ASP.NET Membership Provider model.

    http://our.umbraco.org/forum/developers/api-questions/6145-Use-Member-Or-UmbracoMembershipProvider

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Mar 15, 2010 @ 22:39
    Aaron Powell
    0

    http://www.aaron-powell.com/blog/july-2009/umbraco-member-profiles.aspx 

    That's how. Can be a problem if you've got 2 different membership profiles though, but that's a pure ASP.NET limitation, not an Umbraco one (and I did a reply to a question somewhere which did have a bit of a solution).

  • Simplicio Jison Jr. 24 posts 44 karma points
    Mar 16, 2010 @ 04:10
    Simplicio Jison Jr.
    0

    HI slace,

    I found some sample for Membership and Silverlight.  Although you did not confirm if It can authenticate via Webservices, but in this example it can. I also mark your Reply as Solution.

    http://www.eggheadcafe.com/tutorials/aspnet/7cc2760f-50f2-492d-9d62-48ad5c7f70b4/aspnet-membership-and-ro.aspx

     

    Regards,
    Simplicio

  • Simplicio Jison Jr. 24 posts 44 karma points
    Mar 16, 2010 @ 07:27
    Simplicio Jison Jr.
    0

    I mean its <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> + WCF

Please Sign in or register to post replies

Write your reply to:

Draft