Wednesday, March 28, 2012

PageMethods call - Authentication Failed.

I am working with RC1 and am having problems calling a pagemethod. It keeps telling me Authentication failed. 
My page is using a master page where the Scriptmanager is declared. As you can see I am using a ScriptmanagerProxy on my main page.
The code works fine when forms authentication is not on and everything else on the site works fine when Authentication is on except Ajax pagemethod calls.
Authentication is occurring on my login in page and all of the Athentication is builtinto the codebehinds. My Question. Do I have to implement
Sys.Services.AuthenticationService to be allowed to call an Ajax web service call or pageMethod call when usingFormsAuthenication?
 Here is an incomplete example of what I am trying to do. Missing the login page
// java script file test.jsfunction pageLoad(sender, eventArgs){ PageMethods.TestThis("bar",onTestComplete, OnTestFail);} 
function onTestComplete(result){ alert(result);} function OnTestFail(error){ alert(error._message)}
// code behind[WebMethod]public static string TestThis(string name){return"foo " + name;}
<!-- web config --><system.web><authentication mode="Forms"><forms name="test" loginUrl="Login.aspx" protection="All" timeout="60" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="Default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="true"/></authentication><authorization><deny users="?"></deny><allow users="*"/></authorization></system.web><!-- html page --><asp:ScriptManagerProxy id="ScriptManagerProxy1" runat="server"> <SCRIPTS> <asp:ScriptReference Name="PreviewScript.js" Assembly="Microsoft.Web.Preview> <asp:ScriptReference Path="Scripts/test.js" ScriptMode="Debug"'> </SCRIPTS> <SERVICES> </SERVICES></asp:ScriptManagerProxy>
"Debug"'>Can someone please help me??
"Debug"'>Thanks in advance. 

Ok, Im gonna guess that its probably becasue the pageMethod has to be defined as static, if so is there a workaround?

Or are pageMethods totally useless in site with forms authentication?

Try changing your pagemethod's WebMethod attribute to be: [WebMethod(Session=true)]. That should help w/ the authentication issue.

No comments:

Post a Comment