Der Zugriff auf Unternehmensressourcen aus einer Windows Store App ist denkbar einfach:
1. Als Erstes schaltet man einige Funktionen/Capabilites im Visual Studio Projekt frei (im Package.appxmanifest)
- Enterprise Authentication (Unternehmensauthentifizierung) - Private Netzwerke (Client und Server), wenn der Zugriff aus einem Intranet erfolgen soll -oder- - Internet (Client) oder Internet (Client und Server), wenn der Zugriff aus dem Internet erfolgen soll
- Enterprise Authentication (Unternehmensauthentifizierung)
- Private Netzwerke (Client und Server), wenn der Zugriff aus einem Intranet erfolgen soll
-oder-
- Internet (Client) oder Internet (Client und Server), wenn der Zugriff aus dem Internet erfolgen soll
2. Der Call auf eine URL kann in C# über die Klasse HttpClient erfolgen, wobei eine HttpClientHandler mit den Properties UseDefaultCredentials=true oder PreAuthenticate= true erfolgen kann:
using System.Threading; using System.Security.Principal; using System.Net.Http; //…. try { var uri = new Uri("http://URL_WHICH_NEEDS_DOMAIN_CREDENTIALS" ); HttpClientHandler handler = new HttpClientHandler(); //handler.PreAuthenticate = true; handler.UseDefaultCredentials = true; HttpClient client = new HttpClient(handler); HttpResponseMessage response = await client.GetAsync(uri); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); //Do something with responseBody } catch(HttpRequestException e){ //Do the Exceptionhandling }
using System.Threading; using System.Security.Principal; using System.Net.Http; //….
try {
var uri = new Uri("http://URL_WHICH_NEEDS_DOMAIN_CREDENTIALS" );
HttpClientHandler handler = new HttpClientHandler();
//handler.PreAuthenticate = true;
handler.UseDefaultCredentials = true;
HttpClient client = new HttpClient(handler);
HttpResponseMessage response = await client.GetAsync(uri);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
//Do something with responseBody
} catch(HttpRequestException e){
//Do the Exceptionhandling
}
In JavaScript kann das WinJS.xhr Objekt für den Call verwendet werden, welches Aufrufe von XMLHttpRequest in einem Promise (d.h. asynchronen) Aufruf kapselt:
WinJS.xhr({ url: "http://URL_WHICH_NEEDS_DOMAIN_CREDENTIALS", header: { Authorization: "Windows" } }).then( function (response) { connectionStatus = response.status; }).then( displayURL, displayConnectivityError ); } function displayConnectivityError() { var msg = "Der Server ist nicht erreichbar. Bist Du im Firmennetz?" var div = document.getElementById("msgDiv"); div.className += " msgDivError"; div.className = div.className.replace(/(?:^|\s)msgDiv(?!\S)/g, ''); div.className = div.className.replace(/(?:^|\s)msgDivHidden(?!\S)/g, ''); msgDiv.innerText = msg; } function displayConnectivity() { //Do something with the result } }
WinJS.xhr({ url: "http://URL_WHICH_NEEDS_DOMAIN_CREDENTIALS", header: { Authorization: "Windows" } }).then( function (response) { connectionStatus = response.status; }).then( displayURL, displayConnectivityError ); }
function displayConnectivityError() { var msg = "Der Server ist nicht erreichbar. Bist Du im Firmennetz?" var div = document.getElementById("msgDiv"); div.className += " msgDivError"; div.className = div.className.replace(/(?:^|\s)msgDiv(?!\S)/g, ''); div.className = div.className.replace(/(?:^|\s)msgDivHidden(?!\S)/g, ''); msgDiv.innerText = msg; }
function displayConnectivity() { //Do something with the result } }