I have the following code that finds out if the status of the posted request (to an external api) was successful, and if so, it should navigate to the Interface.xaml page I have created in the windows phone app. Not sure which class deals with navigating between xaml pages
public bool UsernameAndPassword(string username, string password)
{
data = "grant_type=" + GRANTTYPE + "&username=" + username + "&password=" + password + "&client_id=" + CLIENTID + "&redirect_uri=" + REDIRECTURI + "&client_secret=" + CLIENTSECRET;
return true;
}
public bool Authenticate()
{
// form the URI
UriBuilder fullUri = new UriBuilder(urlPath);
fullUri.Query = data;
// initialize a new WebRequest
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUri.Uri);
request.Method = "POST";
// set up the state object for the async request
DataUpdateState dataState = new DataUpdateState();
dataState.AsyncRequest = request;
// start the asynchronous request
request.BeginGetResponse(new AsyncCallback(HandleResponse),
dataState);
return true;
}
private void HandleResponse(IAsyncResult asyncResult)
{
// get the state information
DataUpdateState dataState = (DataUpdateState)asyncResult.AsyncState;
HttpWebRequest dataRequest = (HttpWebRequest)dataState.AsyncRequest;
// end the async request
dataState.AsyncResponse = (HttpWebResponse)dataRequest.EndGetResponse(asyncResult);
if (dataState.AsyncResponse.StatusCode.ToString() == "OK")
{
// What needs to go here to navigate to another xaml page?
// something like this? - NavigationService.Navigate(new Uri("Interface.xaml", UriKind.Relative));
}
}
public class DataUpdateState
{
public HttpWebRequest AsyncRequest { get; set; }
public HttpWebResponse AsyncResponse { get; set; }
}
The problem can be found within the HandleResponse method in the if statement.
// EDIT::
I have now extended the PhoneApplicationPage class which has given me access to NavigationService ... However, when I now execute my program, when I navigate to the new page using:
NavigationService.Navigate(new Uri("Interface.xaml", UriKind.Relative));
it throws a runtime error:
An exception of type 'System.UnauthorizedAccessException' occurred in System.Windows.ni.dll but was not handled in user code
If there is a handler for this exception, the program may be safely continued.
any ideas?