Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Wednesday, March 28, 2012

How do I intercept Authentication Failed exception from web-service call

Will somebody please put me out of my misery. I think this might be a common problem, but I've spent 30mins searching the forum and I can't find a solution...

I have forms-authenticated web app with a page that makes AJAX client-side calls to a web-service that is part of the same application and hence (I assume) is protected by the forms authentication. The problem occurs when the forms authentication ticket has expired. If a user action invokes a call to the web-service they get a message box quoting InvalidOperationException and Authentication Failed etc. I want to try and intercept this exception and re-direct to the login page as usual. I can't see how to do this. I've tried adding a <location> tag to the web.config to exclude the web-service asmx file from the authorisation, but this doesn't work.

The HTTP logs show a 500 internal server error along with this message:

"@dotnet.itags.org._Error(false,"Authentication failed.",null,"System.InvalidOperationException")Error_@dotnet.itags.org."

How can I intercept this exception??

I'll simplify my question:

How do you chaps manage to make AJAX web-service calls co-exist with forms authentication?

If the authentication ticket expires, how do you handle this error from the client (browser)?

I await your prompt and courteous replies!


OK, so I didn't realise you can specifiy a failure callback as well as a success callback when calling a web-service.

That's all I needed, thanks to no-one for helpingIndifferent

Monday, March 26, 2012

How do I catch this error?

I have a simple client side webservice call that has a timeout and error handler defined:

TickUpdates.TickUpdate(tokenKey, SucceededCallback, FailedCallback, FailedCallback);

if I am not connected to the web, I get the following error. How can I capture this gracefully ?

[Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::http://localhost:45000/ScriptResource.axd?d=BSklnKRUU-3ZDmAWzNvjWRmHZJsJaTmhatiwatSzdV-n5b762_YnBv0exMpD6psRGreUx_ficbFeVQuAjTH012_sGHF6tKUojM03BRoiazs1&t=633084179322613693 :: Sys$Net$XMLHttpExecutor$get_statusCode :: line 4166" data: no]
http://localhost:45000/ScriptResource.axd?d=BSklnKRUU-3ZDmAWzNvjWRmHZJsJaTmhatiwatSzdV-n5b762_YnBv0exMpD6psRGreUx_ficbFeVQuAjTH012_sGHF6tKUojM03BRoiazs1&t=633084179322613693
Line 4166

In my case, it's happening because I'm trying to make a call to a PageMethod on a page that required authentication, but my authentication has timed out. In IE, I get an error with status 12030, but Netscape gives me the error above. This is a showstopper if I can't handle it gracefully via the FailedCallback handler.

Any ideas?


OK, so I figured out what's going on. In the Microsoft library, there's the following method:

function Sys$Net$XMLHttpExecutor$get_statusCode() {
/// <value type="Number"></value>
if (arguments.length !== 0) throw Error.parameterCount();
if (!this._responseAvailable) {
throw Error.invalidOperation(String.format(Sys.Res.cannotCallBeforeResponse, 'get_statusCode'));
}
if (!this._xmlHttpRequest) {
throw Error.invalidOperation(String.format(Sys.Res.cannotCallOutsideHandler, 'get_statusCode'));
}

return this._xmlHttpRequest.status;
}

The problem with this is that Firefox throws an exception if the status isn't available, which is the case if you're offline, or, in my case, trying to access a PageMethod on a page requiring authentication after your logon has timed out. Throwing an exception is the W3 standard, as shown athttp://www.w3.org/TR/XMLHttpRequest/. Here is the related text...

status of type unsigned short, readonly
If the status attribute is not available an INVALID_STATE_ERR exception must be raised. It must be available when the state is receiving or loaded. When available, it must represent the HTTP status code (typically 200 for a successful request).

Its initial value must be 0.

So, what does this mean to us? It will require that Microsoft trap the exception thrown when the status isn't available, and then called the FailedCallback method so that we can handle it.


Here's my workaround. You can read the comments to know what I'm doing. With this fix to the get_statuscode method, I can then handle the 999 error code in my FailedCallback function. I hope this helps!

<script language="javascript">
//MS Ajax isn't handling getstatus exception, so i have to insert my own try/catch
//I'm doing it by creating a new prototype method... instead of rewriting the whole
//function, i'm simply taking the text of the current function, changing the name
//via replace, and changing the line accessing status to have try/catch wrapped around
//it. If the status call errors out, i'm returning error 999. You can return whatever you
//want.
//PS. I'm no javascript guru, so forgive me if I didn't use the most efficient
//code for creating a replacement function with the fixes.
//get the current function text
var funcText = Sys$Net$XMLHttpExecutor$get_statusCode.toString();
//our new function will have 'Patched_' appended to the start of the existing function
funcText = funcText.replace('Sys$Net$XMLHttpExecutor$get_statusCode', 'Patched_Sys$Net$XMLHttpExecutor$get_statusCode');
//replace status access with same line, except with try/catch block wrapped around it
funcText = funcText.replace('return this._xmlHttpRequest.status;', 'try {return this._xmlHttpRequest.status;} catch(e) {return 999;};');
//create new function using eval... to use funct = new Function or func = function() {...},
//I'd have to take the funcText and strip the function line and bracket from the beginning and the
//end. I could have done it by removing the first and last lines, but I did it this way instead.
eval(funcText);
//have the prototype method point to the new function instead of the old one
Sys.Net.XMLHttpExecutor.prototype.get_statusCode = Patched_Sys$Net$XMLHttpExecutor$get_statusCode;
</script>


I'm getting this error too in Firefox 1.0.3, but I'm not using any authentication. The oddities are:

1.) The error does not occur during the first asynchronous postback. The first one succeeds, but any subsequent async postbacks give the same error (pointing to the same Sys$Net$XMLHttpExecutor$get_statusCode() function).

2.) The error does not occur when I am using VS2005 in debug mode with a breakpoint at the codebehind event hander that handles the postback. When the code stops at the breakpoint, and I let it continue, the async postback succeeds.

Why would it work in debug mode with a breakpoint, but not in debug mode without breakpoints? Why would it succeed on the first postback, but not any subsequent ones?


This is just a weak opinion, but it sounds like a timing issue. I don't know why, but the pause that's introduced because of the breakpoint may enable it to complete, whereas without the pause it fails for some reason.

The issue I've documented definitely happens for reasons other than authentication. I hope I didn't give the impression that it's the only, or even primary, reason :).

John


FYI, MS has confirmed it's an issue, and is going to try to fix it in the Orcas release. In the meanwhile, they said the workaround I posted seems to be OK (although I'm sure they didn't have time to test it thoroughly - use at your own risk :)).

John


I thought of that, but inserting a System.Threading.Thread.Sleep(2000) call in the codebehind handler doesn't fix it.

I jumped the gun with this post anyway. As indicated athttp://ajax.asp.net/docs/BrowserCompatibilityForASPNETAJAX.aspx, UpdatePanels aren't officially supported for Firefox 1.0.x. Still, shouldn't Microsoft render in such a way that this browser uses synchronous postbacks instead of attempting asynchronous ones?


Then again, I'll have to chalk this one up to my system configuration. I just tried the same code using FF 1.0.3 on a different machine, and everything works as expected. Will have to try it in a production environment to see if the problem isn't coming from VS2005 and its embedded web server.


So it really is a confirmed issue? FYI I tried your fix. Whereas it did stop the error from popping up in the FF javascript console, it did not cause the second async postback to proceed. This is leading me more into thinking the problem was with my system configuration.

Saturday, March 24, 2012

How do I call the animation when hovering over an asp.net menu?

I have a quite simple problem I guess.

My master page has a menu on it, and I want to call my animation fade sequence when hovering over the menu, and call the unfade seqence when the mouse is removed from the menu.

I would have no problem to have the update panel on either my normal pages, or on the master page, as I want to fade everything within the update panel.

Any hints or suggestions are very much appreciated. I would like to name my fade sequence FadePage and call it when hovering. I just can't figure out how to do this, or fade it in any other way.

Thanks

/Jonas

Hi Jonas,

I think I might have misunderstood the problem , but I feel this link will be helpful :

http://blogs.gotdotnet.com/phaniraj/archive/2007/04/13/animations-how-many-ways-do-i-call-thee.aspx

Hope this helps


So if I do like this:

<formid="form1"runat="server">

<scriptlanguage="javascript"type="text/javascript">

function DoTheAnimation()

{//Play the Animation by calling its static methods

AjaxControlToolkit.Animation.ResizeAnimation.play( $get("queryReply") , 0.2 , 45 , 200 , 100 ,"px" );

}

</script>

<asp:scriptmanagerID="Scriptmanager1"runat="server"></asp:scriptmanager>

<asp:MenuID="MainMenu"runat="server".....................>

<ajaxToolkit:AnimationExtenderID="animateReplyPanes"runat="server"TargetControlID="MainPage"BehaviorID="animateReplyPanesBehavior">

<Animations>

<OnClick>

<ResizeHeight="100"FPS="25"Width="200"duration="0.3"unit="px"/>

</OnClick>

</Animations>

</ajaxToolkit:AnimationExtender>

How can I then call the DoTheAnimation function when user hovers over the menu?

Also: what should I write instead ofqueryReply?

Thanks /Jonas


This is probably a much simler and better explanation of what I want to do:

<body>

<formid="form1"runat="server">

<asp:scriptmanagerID="Scriptmanager1"runat="server"></asp:scriptmanager>

<asp:MenuID="MainMenu"runat="server" ........ ..........................></asp:Menu>

<divclass="MainPage" id="MainPage"runat="server">

<asp:contentplaceholderid="ContentPlaceHolder1"runat="server">

</asp:contentplaceholder>

</div>

<ajaxToolkit:AnimationExtenderID="animateReplyPanes"runat="server"TargetControlID="MainMenu"BehaviorID="animateReplyPanesBehavior">

<Animations>

<OnHoverOver>

<FadeOut/>

</OnHoverOver>

<OnHoverOut>

<FadeIn/>

</OnHoverOut>

</Animations>

</ajaxToolkit:AnimationExtender>

So If I have this code, but I want the animation to play on my "MainPage" div instead of the "MainMenu", how can I do that?

Thanks!

How do call javascript function when ajax request is successed

How do call javascript function when ajax request is successed?

Hi,

Please refer to the life cycle on client side.

You can hook a handler to theendRequest event, and call the function here.

Hope this helps.

How configuring IIS to use with AJAX

I'm new to AJAX. How to configure IIS to use with ASP.NET 2.0 AJAX ? Do I need to install anything to IIS so I can call it from localhost - IE....

Need explanation .........

You will need to install ASP.Net AJAX on your dev box so you can use it from localhost and also on your production server for when you deploy your solution.


I still don't understand with install 'dev box ' , what is that mean ?

I have already install ASPAJAXExtSetup.msi for extended AJAX wih my VS2005.

Do I need to install other plugin for AJAX in IIS so I can call it from localhost like dotnetframework in IIS for ASP.net ?

Can U tell me....


Have you tried the steps in this topic:

http://ajax.asp.net/docs/InstallingASPNETAJAX.aspx

It should contain the components you need for AJAX.


dev = development
box = computer or system


Yes I have already install extension for AJAX and it's work find ......

But how if the hosting server doesn't have AJAX, should I copy it myself system.web.extension.dll to my bin folder ......??

Any expert in AJAX that have problem like this ??


if your hosting provider doesn't have ajax install, then there's no way you can run ajax. placing all the DLLs in your bin requires full permission, and that is not possible for provider to grant it to you. ask the provider to install it or switch provider.

Wednesday, March 21, 2012

How can I pass additional parameters to the web service or how can I call a method in the

I have done a ton of research in this area and there just does not seem to be a way to pass any addiional parameters to the Web Service reference in the autoextneder call. Is there a way that this can be done. In my world, the list of suggestion is dependant on other data on my web form or web user control. I had read some references that you might be able to call a method in the code behind page, however everything i have tried on this has failed. Here is a list of what I have attempted

Tried to add query string arguments to the service path property (error is thrown trying to render the page)

Tried to set the service path to a web page (aspx) and then call the code behind method (this also threw error trying to render the page)

Viewed some alternative solutions from vrious posts...however most we out of date t the current release (RC1).

I see that David Reed has an example at Infiinity Loop, however his server is unavailable at this time.

I would love for the auto extender to be able to natively support calling the code behind method of the page or user control that is using it. It would seem logical that the derived suggestion should be able to present a filtered list based on other data. It would be nice if I could pass it an array of string that represent name value pairs of data that I can then access in the web service and pass to whatever is building the list. Anyway just a suggestion...maybe the functionality is there and I just can not figure it out

Please help

>> I have done a ton of research in this area and there just does not seem to be a way to pass any addiional parameters to the Web Service reference in the autoextneder call. Is there a way that this can be done. In my world, the list of suggestion is dependant on other data on my web form or web user control.

With some digging around in the AutoCompleteExtender you may be able to modify the javascript to do this - I've never looked at it personally but that is where I would start. You would need to hijack that part that reads from the target control and add other data to the call.

>> I had read some references that you might be able to call a method in the code behind page, however everything i have tried on this has failed.

The following RC1 example of using a page method works on my system, but it's not going to solve your problem. The page method has to be static, so you won't be able to access any form data.

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@. Register Assembly="BenValidationControls" Namespace="ben" TagPrefix="hauna" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><script runat="server"> [System.Web.Script.Services.ScriptMethod] [System.Web.Services.WebMethod] public static string[] AutoCompleteMethod(String prefixText, int count) { return new string[] { "foo", "baz" }; } </script><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" /> <div> <asp:TextBox ID="TextBox1" runat="server" /> <asp:AutoCompleteExtender ID="AutoCompleteExtender1" ServiceMethod="AutoCompleteMethod" ServicePath="~/default.aspx" TargetControlID="TextBox1" MinimumPrefixLength="1" runat="server" /> </div> </form></body></html>

Thanks for the response. I am looking at modifying from the jvavascript as you have suggested. Here is also what I have found out...

First off the code behind must be in an aspx page and not in a ascx. I am not sure why that should matter but apparently it does. it would be really be nice if I could reference the code behind on either type of file. If you are trying to make a reusable control within your app with the auto complete extender then this is somewhat limiting. Also what I did not know or see document anywhere that this function needed to be static. Once I did that it started working quite well.

Thank you very much on this. This actually helped quite a bit.


You were referring to my derived AutoCompleteExtender that enables callbacks... I had some server issues but its back up and running :) This would solve your problem perfectly.

http://weblogs.asp.net/infinitiesloop/archive/2006/11/15/ASP.NET-Ajax-Beta_3A00_-AutoCompleteBehavior-without-a-Web-Service.aspx

how can I pass a value to a javascript function on image clickBehavior atlas?

Hi Guys, I have the image template below and on imageURL I bind theDBImageName that comes from database via webservices objects. I also call a function DoAdditionalHandling because I need to construct the actual image URL. Now I need to define a click event which I am using theclickBehavior . How can I pass to the function a value that comes from database, let's say how can I passDBImageName field that is being bound to imageURL. Please advice!

<image id=

"ImageThumbPath">

<bindings>

<binding dataPath=

"DBImageName" property="imageURL" transform="DoAdditionalHandling" />

<binding dataPath=

"DBImageALT" property="alternateText" />

</bindings>

<behaviors>

<clickBehavior click=

"ImageClickHandler" />

</behaviors>

</image>

From your event handler, use the sender's dataContext to get the value, like so:

function imageClickHandler(sender, eventArgs){ var DBImageName = sender.get_dataContext().DBImageName;}

I just posted a working exmaple of this to my blog:http://smarx.com/posts/how-to-pass-a-value-to-a-javascript-event-handler.aspx.


Steve,

I asked you also the other day. Can you help me with<atlas:InitialDatarunat="server"id="InitialData1" >

I need to know how to specify the method name and the parameters to method. The example you showed me does not specify it, but it seems like it has its default methods because the web service on that example inherits froma dataservice. Please help me and give me more details if you can. I appreacite your help.


If I understand your question correctly, you want to specify what method to call on the web service (like using "loadMethod=..." on a dataSource in xml-script). Looking at theclass browser documentation for InitialData, it doesn't look like that's possible. :-(

Yes, the example works because it inherits from DataService and provides one method with the attribute [DataObjectMethod(DataObjectMethodType.Select)], so the right thing happens by default.


so any work around? Please advice.

Nothing that I'm aware of (but others please chime in if you have an answer).

I think you'll have to just not use <atlas: InitialData /> and just use your dataSource with autoLoad="true". InitialData is just there to improve performance a little by allowing you to send the data down with the initial page load instead of requiring a second roundtrip to the server.

I'll ping the product team and see if a LoadMethod parameter will be added to InitialData in the future.


is it anyway to specify the method call and parameters ondataSource with autoLoad="true? Please advice Steve!


Yes, just use the "serviceURL=..." and "loadMethod=..." properties on your <dataSource /> xml-script tag. I believe you can just specify <parameters foo="bar" baz="blah" ... /> inside your <dataSource /> to pass parameters.

If you need to databind those parameters, use <binding dataPath="..." property="parameters" propertyKey="foo" />.


not sure how. do u have the syntax of the datasource parameters? how can then I bind it to a dataview?

More explicitly, here's the syntax:

<dataSource id="myDataSource" serviceURL="myservice.asmx" loadMethod="myLoadMethod">
<parameters param1="foo" param2="bar" />
</dataSource>

(Assuming you have myLoadMethod(string param1, string param2); in your web service.)

Databinding your dataView doesn't need to change at all. It's still:

<dataView id="myDataView">
<bindings>
<binding dataContext="myDataSource" dataPath="data" property="data" />
</bindings>
</dataView>

I believe you already had this working in your code from theother thread.


I did that exactly and got a javascript error invalid xml mark up script. On the other example, I have it simply by clicking in a buton. But my other task is when page loads, the data has to be displayed.

I'll look into getting you a full working example.

To follow up on what I said earlier "I'll ping the product team and see if a LoadMethod parameter will be added to InitialData in the future," I checked with the product team, and it sounds like InitialData will have all the functionality of dataSource (so that includes specifying the method to call on the web service and any parameters), but they're not sure of the timeframe.


Thank you! Please email me atnesfrank@.yahoo.com

Steve,

Here is what I am doing but I get invalid xml mark up script. may be the syntax for parameters is diffrent? Please advice!

<dataSource id=

"dataSource1" autoLoad="true" serviceURL="~/AtlasTestService.asmx" loadMethod="GetTestData">

<parameters Code=

"cu0001" paramboolean="true" />

</datasource>


It's probably because your closing tag doesn't match your opening tag. Try changing "datasource" to the correct capitalization: "dataSource".