I'm currently working on a project where remote domains needs to retrieve information of a member based on a member id.
My initial thought was to make use of /base for this, but I'm running my head against the wall because of cross domain policy. Is it possible to, sort of, "grant access" to a base method, somehow? The scenario is as follows:
Domain A (http://www.mydomain.com) makes a call to the Umbraco site (www.umbracodomain.com) /base method which takes a member ID as a parameter. The data returned will be XML containing the info about this member.
I have a weird feeling that I've overlooked something here :-) Any help and/or hint on this is greatly appreciated!
I can call a base method like 'GetMemberById' and get a response, but when i use your javascript, i get no response. So if you have some working demo code, i would really like to see it.
Thanks for diggin' up this old post :-) I'll have to look through my codesnippets when I get home later tonight. Will bookmark this on my phone so I won't forget it ;-)
Alright, so the first step will have to be making the /base method work :-) Can I trick you into posting your code for the base method and the snippet in your restExtensions.config file here? Also, what does it tell you when trying to access the base method by typing it directly in the browser? Sometimes this approach makes it easier to track down errors like nullpointer exceptions and studd like that.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using umbraco.presentation.umbracobase; using umbraco.cms.businesslogic.member;
namespace Ontranet.Test.Code { [RestExtension("test")] public class test { [RestExtensionMethod()] public static string IsAuthenticated(string MemberName) {
Member m = Member.GetMemberFromLoginName(MemberName);
Allow cross domain calls for a base method
Hi all,
I'm currently working on a project where remote domains needs to retrieve information of a member based on a member id.
My initial thought was to make use of /base for this, but I'm running my head against the wall because of cross domain policy. Is it possible to, sort of, "grant access" to a base method, somehow? The scenario is as follows:
Domain A (http://www.mydomain.com) makes a call to the Umbraco site (www.umbracodomain.com) /base method which takes a member ID as a parameter. The data returned will be XML containing the info about this member.
I have a weird feeling that I've overlooked something here :-) Any help and/or hint on this is greatly appreciated!
Thanks!
- Bo
Should also note that the call from Domain A have to be from JavaScript (and no jQuery!)
Nevermind this. I went and used JSONP to simulate a cross domain request. So basically what I did was:
In javascript on the external domain:
And my base method:
Hi,
Do you have a full example i could see ?
I can call a base method like 'GetMemberById' and get a response, but when i use your javascript, i get no response.
So if you have some working demo code, i would really like to see it.
Hi Peter,
Thanks for diggin' up this old post :-) I'll have to look through my codesnippets when I get home later tonight. Will bookmark this on my phone so I won't forget it ;-)
Thanks Bo, i hope you find it.
Hi Peter,
Unfortunately my code for this is scattered to all directions since I got a new hdd and started using DropBox for storing all my codesnippets :-(
I'm curious though, what happens if you make a regular $.ajax call to your base method? Something along the lines of this:
The base method shouldn't really be caring about the callback parameter in this case.
Let me know if you get anything back by doing this :-)
It dosnt return anything, neither from remote web app or from same web app as where the /base call is placed.
Hi Peter,
Alright, so the first step will have to be making the /base method work :-) Can I trick you into posting your code for the base method and the snippet in your restExtensions.config file here? Also, what does it tell you when trying to access the base method by typing it directly in the browser? Sometimes this approach makes it easier to track down errors like nullpointer exceptions and studd like that.
Thanks again.
Bo
Base call:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using umbraco.presentation.umbracobase;
using umbraco.cms.businesslogic.member;
namespace Ontranet.Test.Code
{
[RestExtension("test")]
public class test
{
[RestExtensionMethod()]
public static string IsAuthenticated(string MemberName) {
Member m = Member.GetMemberFromLoginName(MemberName);
if (m.getProperty("isAuthenticated").Value.ToString() == "1")
{
return "true";
}
else
{
return "false";
}
}
[RestExtensionMethod()]
public static string GetMemberById(string memberId) {
Member m = new Member(Int32.Parse(memberId));
return "callback( {\"id\": \"" + m.Id + "\", \"name\": \"" + m.Text + "\"} );";
}
}
}
rest file:
<ext assembly="Ontranet.Test.Code" type="Ontranet.Test.Code.test" alias="test">
<permission method="IsAuthenticated" allowAll="true" returnXml="true" />
<permission method="GetMemberById" allowAll="true" returnXml="true" />
</ext>
A call directly to http://umb_4.7.1.1.com//base/test/GetMemberById/1195.aspx returns:
<value>callback( {"id": "1195", "name": "CustomerName entered in member section"} );</value>
Hi Peter,
sorry for the late response, it's been some rough days lately.
Have you tried to tell the base config to not return xml? returnXml="false"
Also, what happens if you remove the ?callback=? parameter from the ajax call?
Does it return anything if you pass
Into the browser? :-)
I can't make a testsite for this at the moment, so that's why I'm asking all these questions ;-)
is working on a reply...