Silverlight 4 OOB Update process when hosted in enterprise portal - c#

Ok, here is the situation. I would like to deploy a silverlight application to an enterprise portal. Users will access the application by logging in to the portal and navigating to the page where it is hosted. That's the easy part.
This silverlight 4 application is designed to be run in Out of Browser mode (OOB). My question is, is it possible to have the Silverlight OOB update process retrieve updates from behind the enterprise portal's authentication?
When I call App.Current.CheckAndDownloadUpdateAsync();, how do I supply credentials so that this HTTP request will succeed?
Any ideas? Is the update process extensible?
Thanks for your help.

With Silverlight 4 this should be a possible scenario
In both classes WebClient and WebRequest you can use Credentials..
private void DownloadAdditionalThings()
{
WebRequest.RegisterPrefix("http://", System.Net.Browser.WebRequestCreator.ClientHttp);
var client = new WebClient();
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("username", "password");
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri("http://blog.gfader.com/"));
}
private void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string result = e.Result;
}

Related

How can get HTML Agility to authenticate against a Windows Integrated Security app?

I'm trying to use HTML Agility pack to scrape a page of my app and embed it as mail body. That worked wonders on my developpement machine with this answer, but as soon as I published it on the remote IIS server, then I get 401.1 error pages as mail body instead.
The app uses Windows Integrated Security for authentication and authorizations, I have set the service account on the Application Pool. So I tried to set the credentials manually to use the same account as the application pool and added it to the authorized roles, and I still get the same issue.
This is the code I use to get the page:
var lAuthentification = new NetworkCredential("username", "password", "domain");
var lProxy = new WebProxy() { Credentials = lAuthentification };
var lWeb = new HtmlWeb();
lWeb.PreRequest = delegate (HttpWebRequest webRequest)
{
webRequest.Timeout = 1200000;
return true;
};
var lPage = lWeb.Load(pURL, "GET", lProxy, lAuthentification);
I tried both that and the solution linked in the answer mantionned before, which works fine on my machine:
var lProxy = new WebProxy() { UseDefaultCredentials = true };
var lWeb = new HtmlWeb();
lWeb.PreRequest = delegate (HttpWebRequest webRequest)
{
webRequest.Timeout = 1200000;
return true;
};
var lPage = lWeb.Load(pURL, "GET", lProxy, CredentialCache.DefaultNetworkCredentials);
At the top of my controller I have the authorize clauses [Authorize(Roles = #"RoleNames")] because all the data are sensitive.
Many sources explained that when a domain account is set on the App Pool, the SPN must be set, but apparently that was up until IIS6 and we're on IIS8 (Windows Server 2012), so that shouldn't be related I think.
I liked the overall idea, I didn't want to have to build the mail body with string builder and lookup the data off the database if I have a page that already has all the info, so maybe there's a way to fetch the processed razor page without making web request?

How to prevent losing telemetry pageView with Application Insight's Persistence Channel?

when internet connection is available application insights for wpf application works fine and I am able to track page and events in azure portal but I want to know is it possible to store telemetry data somewhere in system when their is no internet connection and retrieve it when system is online and track those actions which I performed when their was no internet connection.
I suggest you take a look at Application Insights for Desktop Applications, it has nice code examples of using Application Insights with desktop applications in general, and also how to work/use the Persistence Channel. Taken from mentioned link:
public MainWindow()
{
TelemetryConfiguration config = TelemetryConfiguration.CreateDefault();
config.InstrumentationKey = "954f17ff-47ee-4aa1-a03b-bf0b1a33dbaf";
config.TelemetryChannel = new PersistenceChannel();
config.TelemetryChannel.DeveloperMode = Debugger.IsAttached;
telemetryClient = new TelemetryClient(config);
telemetryClient.Context.User.Id = Environment.UserName;
telemetryClient.Context.Session.Id = Guid.NewGuid().ToString();
InitializeComponent();
}
And then:
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
...
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
ExceptionTelemetry excTelemetry = new ExceptionTelemetry((Exception)e.ExceptionObject);
excTelemetry.SeverityLevel = SeverityLevel.Critical;
excTelemetry.HandledAt = ExceptionHandledAt.Unhandled;
telemetryClient.TrackException(excTelemetry);
telemetryClient.Flush();
}
Update
To track page views, you can use one of TelemetryClient's TrackPageView overloads, for example:
telemetryClient.TrackPageView("MyPageName");
Hope it helps!

How to send e-mail from within a Win8 Metro App

I am developing a Windows8 Metro App using c# xaml and I have to send the app link as an e-mail to someone using the share contract.
What I have tried is
private void RegisterForShare()
{
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.ShareLinkHandler);
}
private void ShareLinkHandler(DataTransferManager sender, DataRequestedEventArgs e) {
DataRequest request = e.Request;
request.Data.Properties.Title = "Sharing My Link";
request.Data.Properties.Description = "Add a link (URI) to share";
var _Uri = new Uri("https://login.live.com/");
Windows.System.Launcher.LaunchUriAsync(_Uri);
}
And also,
void App_QuerySubmitted(Windows.ApplicationModel.DataTransfer.DataTransferManager sender, Windows.ApplicationModel.DataTransfer.DataRequestedEventArgs args)
{
App.SettingsFlyout.Equals(args.Request, ApplicationExecutionState.Running);
}
But it works in a way where the specified link just opens and not a feature where the email of the link could be sent to soemone.
Any suggestions or solutions please?
While you can use the share charm to let the user sent text if you want to the user to definitely send email (as opposed to Twitter / Facebook) then you should use the mailto protocol.
await Launcher.LaunchUri(new Uri("mailto://test#address.com?subject=email"));
There's no built-in API for sending emails. Microsoft recommend to use share charm to send the email. Though if you want to send email via you need to go for commercial library called Mail.dll
Try this
var mailto = new Uri("mailto:?to=recipient#example.com&subject=Your subject&body=Your text");
await Windows.System.Launcher.LaunchUriAsync(mailto);

Authenticate against UAG using Windows Phone 8 app

I have a very simple scenario - I need my app to automatically authenticate against the UAG gateway. At the moment, I only have a file share application behind the portal, but I'm just trying to do an automatic authentication against the UAG by supplying the user credentials in code. I'm trying to access portal.mylab.com/dummylink - I know this will fail but I want the app to show me it passed the UAG authentication and failed when trying to find this dummylink application
What I have for now is simple, there is just a button in the WP8 app and everything else is hardcoded. I have a simple textblock under the button which shows the response from the website, but I get the authentication page everytime. This is what I have
private void Button_Click(object sender, RoutedEventArgs e)
{
System.Uri targetUri = new System.Uri("portal.mylab.com/dummylink");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUri);
request.CookieContainer = new CookieContainer();
request.Headers["User-Agent"] = "Microsoft Office Mobile";
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes("testuser" + ":" + "Password1")) + System.Environment.NewLine;
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), request);
}
private void ReadWebRequestCallback(IAsyncResult callbackResult)
{
HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(callbackResult);
using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
{
string results = httpwebStreamReader.ReadToEnd();
Dispatcher.BeginInvoke(() => TextBlockResults.Text = results);
}
}
When I look at the textblock, I can see the HTML code being returned for the login page (for a mobile portal), with 2 buttons to login either using a PIN or using credentials. What I expected (or rather wanted) to see is UAG authorization to be successful and get some kind of a "dummylink page not found" type of error. I am supplying the user credentials to UAG but it doesn't seem to be picking them up.
I'm probably missing something very obvious here, and also this is my first time with anything to do with UAG, so please excuse stupid mistakes :)
Thanks in advance
Turns out this approach is completely wrong! IF someone is looking on how to do the above, then please look at this brilliant blog
http://usingnat.net/sharepoint/2011/2/23/how-to-programmatically-authenticate-to-uag-protected-sharep.html

Using a JSON REST Service in Silverlight 4

I need to use a JSON REST Service inside my Silverlight Application so that I can display information from the REST service in my Silverlight App. Below is my code but the ClientDownloadStringCompleted() is never stepped into and I'm not sure why. The REST service does have data and is working. I just can't seem to access it so I can parse out the data I need. View of the JSON Service
string jsonlink = "http://hou-prodserver2/ArcGIS/rest/services/sar/ScheduledRig/MapServer/81/query?text=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=MAXDATE%3E%271%2F1%2F1900%27&time=&returnCountOnly=false&returnIdsOnly=false&returnGeometry=false&maxAllowableOffset=&outSR=&outFields=MAXDATE&f=pjson";
var client = new WebClient();
client.DownloadStringCompleted += ClientDownloadStringCompleted;
client.DownloadStringAsync(new Uri(jsonlink, UriKind.Absolute));
Below is Method I'm trying to use to get access to the data but it never gets used
private void ClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
//handle the response.
string result = e.Result;
}
Make sure that service site has one or both of the following files at the root of the site:
crossdomain.xml
clientaccesspolicy.xml
If your Silverlight app is not on the same exact domain as the service, those files need to exist to allow it to connect. If they don't Silverlight fails silently.

Categories

Resources