How can I refresh browser in silverlight 4 application? - silverlight

I have an Silverlight 4 application, in log-in process I have some validations and data preparation, for any reason in each step if I get an exception, I want to stop my application and refresh the browser but I want save my exception message from my last session and then update my error text block in log-in screen and inform my user about exception message.how can I save my variable in session and then refresh browser?

On silverlight side you may use HtmlPage namespace ,
Beside this refreshing a page in silverlight is not a good practice,and shows your app. as if broken.Siverlight is a RIA. using benefits of this Rich platform is better I think.
HtmlPage.Window.Navigate(HtmlPage.Document.DocumentUri, "_self");
/* You may also add Query String to your URL as Bryant said,
Uri myUri=new Uri(HtmlPage.Document.DocumentUri.toString()+ "?Exception=True", UriKind.RelativeOrAbsolute);
HtmlPage.Window.Navigate(myUri, "_self");
*/
Hope helps!

Just take the current url and append your error message to the query string and then use javascript to open the current page to that url. You can then get the query string from silverlight to get the error message.

Related

Xamarin forms - Periodic list view data refresh

We are building Xamarin forms app to run on iOS, Android and Windows 10. We are data binding view model to UI which has List View control. We want the data to be refreshed from rest service, every 3-5 seconds when user is viewing the app. We don't want the data to refresh when app is in background, but refresh the data as soon as app is foreground. I tried using Xamarin.Forms.Device.StartTimer and await Task.Delay, but this does not seem to be working very well, sometimes the data does not refresh when not in interactive debug mode especially with Xamarin.Forms.Device.StartTimer , I am not sure what is going wrong as I am not able to do logging on device. On using await Task.Delay, sometimes the Task gets cancelled. In app onresume event, code makes rest service call which fails with connection refused error.
So I wanted to know which is the best way to handle data refresh, any ideas?
Thanks in advance
At last to do periodic refresh, i used Task.Delay and a boolean variable to known whether refresh needs to be performed or not. If user navigates away from the page, i set the boolean variable to false to stop the refresh.

Working around AntiForgeryToken to post form data

I am currently writing a website that will eventually be used as a stand-along application. As a result, I created an MVC application and handle the login through a form. It then redirects to another page which is essentially all the user will see for a while. Until the rest of the application is completed, this entire website will be viewed by the users within a WPF application's WebBrowser control as part of that application.
Since the user must log in to the WPF application, I would like to keep them from having to log in twice. So, my WPF application has code to navigate to the login url and post the data as follows:
Uri linkUri = new Uri("https://www.myURL.com/Account/Login");
ASCIIEncoding encode = new ASCIIEncoding();
byte[] postData = encode.GetBytes("grant_type=password&username=" + _user.UserName + "&password=" + _user.Password);
string postHeaders = "Content-Type: application/x-www-form-urlencoded";
this.myWebBrowser.Navigate(linkUri, null, postData, postHeaders);
Based on Fiddler, I think I am sending the data correctly. However, when the WebBrowser displays, it shows the error page with
The required anti-forgery cookie
"__RequestVerificationToken_L1NjaGVkdWxlci5XZWI1" is not present.
Since I never load the initial page with the AntiForgeryToken, this is expected. However, I was wondering if there were a way around this issue. For example, is there a way to silently load the form and post it without the user seeing it? Or, am I stuck just removing the AntiForgeryToken for now until the site is no longer used within WPF?
Thanks in advance!
Use OAuth to authenticate users from the third party site.

Handle error in AngularJs if iFrame page post throws exception

I have a web application that needs to display dynamically created MS Word files and it has following constituents:
A web service that returns the Word file Stream
An intermediate server page that calls the web service and writes the stream to Response
A web page (built in AngularJs) that collects user inputs and posts data to the intermediate page. Input also contains a file that user uploads from his computer.
From the AngularJs page, I post data to the intermediate page using a hidden iFrame. Entire setup works well and when the user clicks Submit and the browser duly shows Open/Save/Cancel dialog.
How do I display a message if web service throws exception? I am not able to catch it from AngularJs code.
PS: I can use the intermediate page to display the message in iFrame but then I need to clear it out when user takes another action on the form. How can I do that from AngularJs?

Windows Phone show ConnectionSettingsTask and back

I am working on a windows phone app right now.
In the app, I am handling an exception in page 1, that when there is no wifi connection, it will pop a XNA messagebox, user can choose to open the WIFI settings page. I have the following code:
ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.WiFi;
connectionSettingsTask.Show();
But the problem with this is, when user hit back key in the wifi settings page, they will be navigate back to page 1, which has a loading problem and can not display the proper content. In this case, I would like user to directly go to another page, call it page 2.
Is that possible? Thank you
++++++++++++++Update
Is there are way to customize the back key functionality when showing the XNA messagebox?
I don't know about XNA coding much, but I do know that if you return from wifi connection page to your app, the OnNavigatedTo function is invoked. Try setting out your flow of code according to the application flow. If there is some code you have executed at the constructor, shift it to OnNavigatedTo and vice-verse, which may solve your problem. Also if you want to shift to another page, do it in the same function (OnNavigatedTo) itself. Hope it helps.
Maybe you can change the navigation behavior: http://blogs.msdn.com/b/ptorr/archive/2010/08/28/redirecting-an-initial-navigation.aspx
However it is recommended to merge the two pages together (hide loading bar and show main page) as you will have less problems...
why not handle this code in the IsNetworkAvailable check? that way you'l avoid the exception altogether

Showing the result of a WebClient-postback in an Browser Window from Silverlight 4

I want to show the result of a WebClient-Postback in an new Browser-Popup-Window. As the "Navigate" and "Popup" methods of HtmlPage only support Get-requests, I issued an POST-request to an REST-Service via WebClient. But now I want to show the result (e.g. application/ms-excel or application/pdf) in an new Browser-Window.
Therefore, can I open an new BrowserWindow and set its contents as well as some corresponding http-headers with on-board means of Silverlight 4? Or even better, is an easier way to trigger the browser to do the POST-request to the service?
Best Regards
I tried going this route but the WebBrowser control is not opened to the developer. What I did as a temporary workaround was to open my webpage http://www.xyz.com/default.aspx inside the WebControl and let the page drive the rest.
Mike Taulty had an example for somthing like this, how you can use javascript to communicate back to the silverlight app through InvokeScript:
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-html-hosting-in-the-webbrowser-control.aspx
I hope it helps!

Resources