How to resize Webbrowser content to fit 480 x 800 - c#

Im using some basic code to display a mobile website in my application using a web browser.
For some reason, if I use the standard browser it is sized correcly to 480 x 800 , but when I use the web browser in my application the page is way off more like 960 x 800.
Is there a way to force the size the page is displayed in the web browser?
The funny thing is that it was working a few months ago, but has suddenly gone haywire.
code is :
string site1 = "http://m.domain.com";
webBrowser1.Navigate(new Uri(site1, UriKind.Absolute));
webBrowser1.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(webBrowser1_Navigated);
I was thinking I could force user agent by using the below code, but I am getting errors " no overload for method, 'Navigate' takes 4 arguments.
webBrowser1.Navigate("http://localhost/run.php", null, null, "User-Agent: Windows Phone 7");
Page using app:
Page using standard IE9 browser outside of application, but on handset.

One place to start would be to sniff the request/response. There's clearly different HTML coming back from the server for the two requests. For the in-app browser, it clearly says it's having trouble identifying the device. If you can figure out what is different between the two requests, you might be able to force the in-app browser to make the request more like the out-of-app browser.
If you're using the simulator, Fiddler is a fantastic tool for that sort of thing. The first place I'd look is at the User-Agent header, which most sites use to figure out what type of browser is requesting the page.

Related

Application Insights missing browser info

I added Application Insights to my web project using Application Insights button in Visual Studio 2017. After that I've added JavaScript code to View\Shared\_Layout.cshtml as described here
After a week of monitoring I found that there is missing some information about client browser, OS, etc.
The following query returns only client_Type with PC value (but should also Mobile)
requests
| project client_Type, client_Browser, client_Model, client_OS
Why it is empty? What I missed? Should I add some configuration to store that info?
requests might not have browser info. that comes from the server side, so i want to say it gets everything from the UserAgent header of inbound requests.
however, the javascript code in your layout.cshtml enables PageView telemetry, which collects more information from the browser.
things to do:
1) make sure your backend (whatever is sending requests) is using the same ikey as whatever you have in your javascript snippet, to make sure you looking at the same data for both things
2) look at what's in both tables and see if it is different:
union requests, pageViews
| where timestamp > ago(14d)
| summarize count() by itemType, client_Browser
| render barchart
i bet you get a bar chart that has requests with one giant bar for one browser (empty), and a different bar for pageViews that has lots of browsers?

Facebook Graph API Requests from .NET (C#)

I have an application that generates a web request to Facebook Graph API to get a share count from an external page. I have been using this code for over a year without issue, and suddenly, the share count is not working when the request is made from .NET. However, if I make the request from a web browser, it works just fine. My code is as follows:
string fbLink = "https://graph.facebook.com/?id=" + externalLink + "&fields=og_object%7Bengagement%7D&access_token=<token_removed>";
WebClient client = new WebClient();
string fbString = client.DownloadString(fbLink);
This code still appears to be working fine, in that the request is made, and FB responds with no errors. In fact, it responds back with correct page id, and details. However, the share count is zero.
Here is where it gets a little bit weird. On my localhost development machine, the code works fine and returns the proper share count. However, if I run the code on my actual server (an AWS EC2 instance), the share count shows zero.
If I open Chrome and run the request from the browser, the share count displays as expected.
If I open Internet Explorer 11, and run the request from the browser, the counter shows zero. HOWEVER, if I log in to Facebook from IE11, and then run the request to FB Graph API, the response shows the correct page count.
This is very confusing to me, as it appears the reason the counter has stopped working, has to do with cookies, or maybe the browser being logged into FB. This should not be the case as I am using an APP token ID, and I wouldn't expect to need to be logged into FB in order to make a request to Graph API.
Does anybody have any ideas why my request/code in .NET worked just fine for a year and a half, and just stopped working? Or why the requests work fine on my localhost and not my live server?
After spending considerable time on this issue, I have fixed the issue. There is a FB authentication cookie that was being transmitted through a web browser query. The cookie name was "XS" and the value was a long string that is used as a sessionId for my specific login. If I created this cookie in my web request in C# code, I get the proper response with correct # of shares.
WebClient client = new WebClient();
client.Headers.Add("Cookie", "xs=<removed>;");
I have no idea why I have to do this, only on my EC2 server. Nowhere in FB's documentation does it say you have to spoof a valid logged in authentication string cookie in order to obtain correct Share Count results from a request to it's Graph API, but there you have it. A workaround at least.

Keep getting Error: redirect_uri_mismatch using youtube api v3

Hi I hope someone can help me out here.
I have a Web Application (asp.net) on my local machine, I am trying to upload video to YouTube using this sample https://developers.google.com/youtube/v3/code_samples/dotnet#upload_a_video
I have set up client id and secret for Web application in Google console when I try to upload video a browser tab opens to select one of my google accounts and once I sig in I get redirect_uri_mismatch the response details on that page are below:
cookie_policy_enforce=false
scope=https://www.googleapis.com/auth/youtube.upload
response_type=code
access_type=offline
redirect_uri=http://localhost:55556/authorize/
pageId=[some page id removed here for security reasons]
display=page
client_id=[some unique id removed here for security reasons].apps.googleusercontent.com
one interesting thing is that the redirect_uri=http://localhost:55556/authorize/ is completely different from the one set up in Google console and the one in client_secrets.json also each time I get the error page the port number changes.
redurect urls and origins are set as follows in Google console I think I have added all combinations just in case:
Authorized redirect URI
http://localhost/
https://localhost/
http://localhost:50169/AddContent.aspx
https://localhost:50169/AddContent.aspx
http://localhost:50169
Authorized JavaScript origins
http://localhost/
https://localhost/
http://localhost:50169/
https://localhost:50169/
I am not sure why redirect-uri on the error page does not match any of the
Authorized redirect URI I have specified in Google console ? any ideas ?
Also is it possible that everything is set-up correctly in Google console and my code but this error is triggered by something else like maybe I missed some setting on my you tube account ? I did not make any setting changes since I don't think I have to is that correct ?
Ok I belive that direct video upload to the website owner account is no longer supported in YT API v3.0 according to those posts.
Can YouTube Direct Upload to a Common Account for All Users?
How can I get the youtube webcam widget to upload to one account using API?
Shame, I think I will need to host the videos that users upload on my servers.
However the original issue was fixed by adding this URI to the redirect URIs in the developer console
http://localhost/authorize/
Google OAuth 2 authorization - Error: redirect_uri_mismatch
I got it to work by setting the Redirect URIs to exactly this:
http://localhost:50517/signin-google
Note:
- it does not work with a trailing slash
- port number is whatever your visual studio is assigning
- I set JavaScript Origins to:
http://localhost:50517/
With you, though, would be nice if someone actually documented this somewhere...
You should look into your code where you create the authorization URI. You need pass one of the redirect URIs you registered with Google developer console. I guess you're using some OAuth2 library which uses the localhost:port/authorize as the default redirect URI. The port changes because each time you start your local server, it picks a different port number. To fix it, you should specify a port number when starting it, for example, 8080. Then you should register localhost:8080/AddContent.aspx in Google developer console and pass it to whichever library you use to create the authorization URI.
I experienced a similar problem when trying to setup the quickstart app for the Drive REST API. I kept getting the redirect_uri_mismatch error and the port number with that error kept changing. The fix for me was to change the redirect URI in the Google Developers Console for my app to not include the port number.
There is a really easy way to get round this and I kicked myself when it dawned on me.
I am using "Web Application" credentials - you'll want the credentials manager open btw.
Run the DotNet sample app and let the browser open (I get the "Select An Account" page) - then look in the URL for the redirect URI that's been automatically generated by Google's code something like:
redirect_uri%3Dhttp://localhost:62041/authorize/
Then just go to the credentials manager and add this URL to the allowed list and save. Now select your google account and see what happens - it takes a few minutes for the API to update - if you get the redirect error page just hit back and select you account again - eventually it works and returns back to visual studio.
Once the account has been authorised once it sticks (clear the bin directory to unstick it) but this means you can now put a break point in the code and look at the credentials variable to get the refresh token everyone is so desperately trying to get so that you can persist account connections.

Control the browser through c# or some other way

Okay I know c# got a vast and very ease to use application development programs but this is what i want to learn now.So when user opens his browser and enters some url in it. Is it possible to send this data or the entered url addressto some other code one such a c# code or some other example c++ which is located on his hard drive.
To be simple when user clicks some link on a webpage or enters some url or closes the browser or when he opens the web browser, Can we detect all his actions that he perform on web browser through c# code or anyother way(I guess add-on or pluins the way it works) but Is it possible to send his actions to c# code and program it and give certain output back to browser so that browser performs it and outputs to user.
Something like browser-->c#code-->website.. I want c# code to act between the browser and webpages.
work I tried so far
I started googling on this and learnt little about how browsers work but still unable to find the solution. However I guess plugins are the way to do such tasks and found firebreath cross platform,a way to develop plugins for browsers. So is this possible by plugins? if so could you suggest me some good tools to develop my own plugins. Thanks
There are several options depending on what you want to achieve:
Proxy
You could implement a http proxy and configure the browser to use that proxy. The proxy sees all traffic and can do whatever it wants... this works rather "browser-agnostic". See the links here and here.
PlugIn
You could implement a plugin... alhtough this a browser-specific... for example IE used to have BHOs to this kind of stuff (not sure whether this is still possible with IE10...). Some options can be found here, here, here, here and here.
You can use FiddlerCore for this
Fiddler.FiddlerApplication.BeforeRequest += sess =>
{
Console.WriteLine("REQUEST TO : " + sess.fullUrl);
sess.bBufferResponse = true;
};
Fiddler.FiddlerApplication.Startup(8877, true, true);
Console.ReadLine();
Fiddler.FiddlerApplication.Shutdown();
System.Threading.Thread.Sleep(750);
After running this code, open your browser and navigate to any page.

saving page source using web browser vs HttpWebRequest class from C#

It happens that when I save a web-page source from IE it differs from source downloaded by HttpWebRequest in my C# app.
I have saved both files for reference. The one saved from IE is here and the one from HttpWebRequest is here.
They differ in formating and in the content itself. It seems that the one downloaded by HttpWebRequest is broken and doesn't consist of valid data (which is perfect when saved from IE).
I don't know why I cannot achieve a nice formated source using IE.
Reagrds
Mariusz
I suspect the one downloaded using IE has got some state associated with it from either cookies or session variables that were set when you visited the site manually. The one downloaded using C# will have the default values for everything, and hence different content.
This looks most likely because the file_web file contains a section called "LastViewedHotels" that contains an entry for the Arora Manchester.
Additionally, it looks like there is dynamic content for displaying adverts, which is different between the two files.
Usually this happens when the site you are navigating to, loads additional content via Ajax or frames.
To overcome this and always fetch the content IE sees, you can use the WebBrowser control to navigate and take the source from there.
Here is an
Example
Update
From running a KDiff on the sources you gave, it looks like there's 1 major line difference:
<link rel="alternate" type="text/html" hreflang="de"...
And that looks like it has an ID generated from a session (a cookie) so there's not much you can do about that without copying the IE cookie header.
Previous answer
"Under the hood", IE and HttpWebRequest both perform the same simple task, which is to send the following text request on port 80 via a a socket to the HTTP server:
GET / HTTP/1.1
(or 1.0 - and a host header too).
If you're on Windows you can try it out. Install the built in Windows telnet client (add/remove programs->windows features), or putty and then type:
GET / HTTP/1.1 (newline)
Host: yahoo.com
The source from this, IE, and the HttpWebRequest class will be exactly the same. The only difference will come if IE is passing cookies to the server, and any extra header which normally include:
A user agent
Accept */*
Gzip
A cookies or session variable (which includes session variables - cookies that expire when IE is closed)
For formatting, IE might turn tabs into spaces, or the other way around. The HttpWebRequest will return the raw results without any formatting.

Categories