I need to get a cookie from webview control (W 8.1, c#, xaml).
First I load the page inside the Webview like this:
<WebView x:Name="WebviewControl" FrameNavigationCompleted="Webview_FrameNavigationCompleted" />
WebviewControl.Navigate(new Uri("example.com"));
Then, the user log inside tha page and I need to get the cookie.
I try this:
private void Webview_FrameNavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
HttpBaseProtocolFilter baseFilter = new HttpBaseProtocolFilter();
foreach (HttpCookie cookie in baseFilter.CookieManager.GetCookies(new Uri(sender.Source.ToString()))
{
if (cookie.Name.Equals("cookieName"))
{
string value = cookie.Value;
}
}
}
The problem is that the cookie dosen`t exist inside the cookiemanager.
I doing something wrong?
Related
there is a webview in my UWP app. By default the webview does not show the currently loaded contents url. Is it somehow possible to display the url as in the browser search field for instance?
For example if google is loaded in the webview i want to see the url "https://www.google.de/?gws_rd=ssl" somewhere.
Best wishes
You could show the url in a textbox in the NavigationStarting event
void webView1_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
{
string url = "";
try { url = args.Uri.ToString(); }
finally
{
address.Text = url;
appendLog(String.Format("Starting navigation to: \"{0}\".\n", url));
pageIsLoading = true;
}
}
https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.navigationstarting.aspx
I am working with Xamarin forms and I need to disable the Master page that I use as context menu depending on whether user is logged in or not. I have both Master and Detail pages as separate XAML pages.
<MasterDetailPage.Master>
<view:MenuPage/>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<view:MainViewPage
x:Name="MainView"/>
</MasterDetailPage.Detail>
As you might have guessed, I am trying to incorporate MVVM here, so I tried binding visibility (IsVisible) and enabled (IsEnabled) properties of the Master page, however, I still get the undesired black fade effect when pushing navigation button to access my menu. Instead, I need to completely eat up the button press action.
Should your pages be visible whenever the user is connected or not ?
Or do you have a login page at the start of the application for example ?
If you don't have pages that are visible by both connected users or not, you could implement the login page or another page by defining it as ContentPage. It will take all the screen space and hide the navigationBar.
Then after user connect you call a page as MasterDetailPage and then you will have your navigationBar, ...
Don't know if that's what you're looking for but i hope i was able to help you.
This can be achieved with a custom NavigationRenderer, by overriding the Click event of the drawer icon with your custom logic.
[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNavigationPageRenderer))]
namespace RTW.Mobile.App.Droid.Renderers
{
public class CustomNavigationPageRenderer : NavigationPageRenderer, IMessageSender
{
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
for (var i = 0; i < toolbar.ChildCount; i++)
{
var imageButton = toolbar.GetChildAt(i) as ImageButton;
var drawerArrow = imageButton?.Drawable as DrawerArrowDrawable;
if (drawerArrow == null)
continue;
//ensure only one handler is registered
imageButton.Click -= imageButton_Click;
imageButton.Click += imageButton_Click;
}
}
private void imageButton_Click(object sender, EventArgs e)
{
if (!App.IsBlockingConditionTrue)
{
MessagingCenter.Send<IMessageSender>(this, "ToggleMasterIsPresented");
}
}
}
}
Then just subscribe to the message with
MessagingCenter.Subscribe<IMessageSender>(this, "ToggleMasterIsPresented", OnToggleMasterIsPresented);
and handle it.
private void OnToggleMasterIsPresented(IMessageSender obj)
{
_masterDetailPage.IsPresented = !_masterDetailPage.IsPresented;
}
I am in the process of making a multi tab browser and have run into some problems. I would like it so when the user has added a new tab using a button, that every site they then choose to navigate to will update to the tab url. So if the user changes tab or opens a new one, it the last website will be saved if they return to the previous tab.
Here is the code while creating a new tab & When a tab is selected from the created ones
private void addNewTab(string url)
{
TabEntry urlObj = new TabEntry();
urlObj.URL = url;
urlObj.timestamp = DateTime.Now.ToString("HH:mm");
if (url.Contains("/"))
{
urlObj.Name = url.Remove(url.IndexOf('/'));
}
else
{
urlObj.Name = url.Remove(url.IndexOf('.'));
}
tabs.Insert(0, urlObj);
listBoxTabPage.ItemsSource = null;
listBoxTabPage.ItemsSource = tabs;
Browser.Navigate(new Uri("http://www.google.com", UriKind.Absolute));
//selectedTab = listBoxTabPage.SelectedValue as TabEntry;
}
private void ListBoxTabPage_SelectionChanged(object sender, GestureEventArgs e)
{
selectedTab = listBoxTabPage.SelectedValue as TabEntry;
Browser.Navigate(new Uri("http://www." + selectedTab.URL, UriKind.Absolute));
PivotItems.SelectedItem = BrowserPage;
}
Here is the code where it should update the selected tabs url, in the Browser_Navigated methord
void Browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
_deactivatedURL = e.Uri;
_progressIndicator.IsVisible = false;
string url = Convert.ToString(e.Uri);
//selectedTab.URL = url;
addHistoryRecord(url);
}
Where it is commented out I think is the problem. I believe the code does not know which one is the selectedTab. To fix this error should I create a methord which updates the url of the tab, each time the browser navigates. And how would the program know which tab is currently in use.
If you need any more details please comment and I will be happy to explain in further detail.
You just set listBoxTabPage.ItemsSource = null before you set tabs as ItemsSource. It may clears your listBoxTabPage.SelectedValue.
I think you can just set listBoxTabPage.SelectedValue = urlObj in addNewTab().
Then you begin navigate to a new uri in ListBoxTabPage_SelectionChanged, but it seems to be wrong that you just append a prefix string http://www. to an full url. It may triggers NavigateFailed event if you navigate to a non-exist website.
Browser.Navigate(new Uri("http://www." + selectedTab.URL, UriKind.Absolute));
What's more, ListBoxTabPage_SelectionChanged may triggers twice because the old value is cleared and the new value is set.
I have been trying to figure out if it is possible to open the Sitecore media library browser programmatically from ASP.NET code-behind on a server-side button click. By searching the net, I found an example which explained how to open a media library browser from a Sitecore thumbnail click. I tried this approach on ASP.NET server-side button click but it did not work failing with object reference not set to an instance of an object.
Can anyone please help me if you know how to open the Sitecore media browser in a modal dialog via a server side button click?
My code:
protected void btnShowMediaPopup_Click(object sender, EventArgs e)
{
Database masterDb = Factory.GetDatabase("master");
UrlString url = new UrlString(UIUtil.GetUri("control:Sitecore.Shell.Applications.Media.MediaBrowser"));
Item folderItem = masterDb.GetItem("/sitecore/media library/Images");
url["ro"] = folderItem.Uri.ToString();
SheerResponse.ShowModalDialog(url.ToString(), true);
}
I found a solution. Steps as follows:
a. Created config file "MediaBrowser.config" and added into folder App_Config/Include (configuration xml below):
<configuration xmlns:patch= "http://www.sitecore.net/xmlconfig/">
<sitecore>
<commands>
<command name="example:MediaBrowser" type="SitecoreTraining.HelperClasses.MediaBrowser,SitecoreTraining" />
</commands>
</sitecore>
</configuration>
b. In my ascx control markup added the following to open the media browser:
<A class="scChromeCommand" title="Open Media Browser" onclick="javascript:Sitecore.PageModes.ChromeManager.postRequest('example:MediaBrowser(id=<%# Sitecore.Context.Item.ID.ToString() %>)',null,false)" href="#"><IMG alt="Open Media Browser" src="http://localhost:2438/temp/IconCache/applications/16x16/photo_scenery.png" width="16" height="16" /></A>
c. Created a MediaBrowser class that inherits the sitecore Command class with the following main methods used:
public override void Execute(CommandContext context)
{
Item item = context.Items.Length == 0 ? Context.Item : context.Items[0];
contextItem = item;
var parameters = new NameValueCollection();
wizardPipeline = Context.ClientPage.Start(this, "Run", parameters);
}
protected virtual void Run(ClientPipelineArgs args)
{
Database masterDb = Factory .GetDatabase("master");
if (args.IsPostBack)
{
var itemID = args.Result;
}
else
{
UrlString url = new UrlString (UIUtil .GetUri("control:Sitecore.Shell.Applications.Media.MediaBrowser" ));
Item folderItem = masterDb.GetItem("/sitecore/media library/Images" );
url["ro" ] = folderItem.Uri.ToString();
SheerResponse.ShowModalDialog(url.ToString(), true );
args.WaitForPostBack(true );
}
}
I need to be able to place the captcha image into a picturebox on my form, the reason being that I need to zoom the captcha image for the visualy impaired users.
It appears to be such a simple task, just take the image from the web page and put it into a picturebox but it is turning out to be not so simple.
i have WebBrowser control in form and for registration in one of site, i need captcha image in picture box. problem is that captcha image is generated by JavaScript, when java script runs then it gives url of captcha image. but every time when java script runs, captcha image goes change. i just want that captcha image which is on WebBrowser control current page.
Any help would be greatly appreciated.
here is my code.
public void FacebookRegistration()
{
HTMLDoc = (mshtml.HTMLDocument)WBrowser.Document.DomDocument;
iHTMLCol = HTMLDoc.getElementsByTagName("input");
foreach (IHTMLElement iHTMLEle in iHTMLCol)
{
if (iHTMLEle.getAttribute("name", 0) != null)
{
strAttriName = iHTMLEle.getAttribute("name", 0).ToString();
if (strAttriName == "firstname")
{
iHTMLEle.setAttribute("value", FirstName, 0);
continue;
}
if (strAttriName == "lastname")
{
iHTMLEle.setAttribute("value", LastName, 0);
continue;
}
if (strAttriName == "reg_email__")
{
iHTMLEle.setAttribute("value", EmailID, 0);
continue;
}
if (strAttriName == "reg_passwd__")
{
string s = GetRandomString();
Random ran = new Random();
iHTMLEle.setAttribute("value", s+ran.Next(1111,9999), 0);
break;
}
}
}
iHTMLCol = HTMLDoc.getElementsByTagName("option");
foreach (IHTMLElement iHTMLEle in iHTMLCol)
{
try
{
if (iHTMLEle.innerText.Contains("Male"))
{
iHTMLEle.setAttribute("selected", "selected",0);
}
if (iHTMLEle.innerText.Contains("Jun"))
{
iHTMLEle.setAttribute("selected", "selected", 0);
}
Random ran = new Random();
if (iHTMLEle.innerText.Contains("4"))
{
iHTMLEle.setAttribute("selected", "selected", 0);
}
Random ran1 = new Random();
if (iHTMLEle.innerText.Contains(ran1.Next(1920,1985).ToString()))
{
iHTMLEle.setAttribute("selected", "selected", 0);
}
}
catch { }
}
iHTMLCol = HTMLDoc.getElementsByTagName("input");
int i = 0;
foreach (IHTMLElement iHTMLEle in iHTMLCol)
{
string s = iHTMLEle.className;
if (iHTMLEle.className == "UIButton_Text" && iHTMLEle.getAttribute("value", 0).ToString() == "Sign Up")
{
if (i != 0)
{
iHTMLEle.click();
break;
}
i++;
}
}
private void WBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (CurrentSocial == "facebook")
{
FacebookRegistration();
}
}
}
in the registration page of facebook.com, there is captcha and if you go to page source then you will see only this:
<input type="hidden" id="captcha_persist_data" name="captcha_persist_data" value="AAAAAQAQiCw5zhFGOsVF6TbDBX8d_wAAAGvqENqFy5KkvMip5AIv3QSF7BS7goiHfAC7fTkzr8hW61cq3s1d23Tw7m-WAi-21Uzt1l3frkLf4obBEuZZMwga_hbcUhnWXu4P382QsJ7J0WtAbo5USXWuVjzv_KD1SMyTWhf34AGorQd27dFqZc0a" /?;
and in this input tag, i found url of that javascript which gives captcha url
javascript url: http://api.recaptcha.net/challenge?k=6LezHAAAAAAAADqVjseQ3ctG3ocfQs2Elo1FTa_a&ajax=1&xcachestop=0.31520985781374&authp=nonce.tt.time.new_audio_default&psig=H48rD9d3_QogBfxxKAmzFZ7CG10&nonce=hl77BQn58EsYsPpPwQ2TIA&tt=r3zaWETv27-0igoIw5ndwnHt_W4&time=1256413208&new_audio_default=1
if you browse this url you will get captcha url like this:
var RecaptchaState = {
challenge : '02UflxsCli4nYg-oG48n5bNDm6ywMlvE62UwXQssF__eJAfSiv2TXuac-1tbu2FThwakgH65IdExWDy9qyr1sYbRuwyQFZD7Dk1eE_fXuoSn9tliqnYeMq__LEF6-GTEm0H6TChOtvpwL2G3C1BsBriw8FFaKqkaTwbNoJeAfzI_j9qYnPaqtHJYillevhRsxyaQVYfLvqai7p0Sfu3849BFpamlbfE3to3KTXi5cZ0xlmuGkMkuZhvq_GyK_z-ZXq9z_Ls8xZlywN0jlIOsSEvI9QJq_69X-X3Moq9lFBcmqWYaKbf7faRQt19aJGB4DdBC1PqQIC',
timeout : 25000,
server : 'http://api.recaptcha.net/',
site : '6LezHAAAAAAAADqVjseQ3ctG3ocfQs2Elo1FTa_a',
error_message : '',
programming_error : '',
is_incorrect : false
};
Recaptcha.challenge_callback();
and original captcha url look like this:
http://api.recaptcha.net/image?c=027CxC4LbBbzVJKy-1xX_wRBf7Gmi4AvgikDVaKeYjBCmiX4XBzGymWC7XRfWx4LLQgfscKnfeB7U305MhlVN0X4vAkrK84ac3jybRJ3UJPUQ8rnlJOS7lqNqpRpolYSd6WBxMShhrzqbx-5ScL0JAsN7cJRMLMqeQsPHg1QB7g4kp4KxKO1aEONsUibahnCC8baLHGSIYJ5Q1Gcr1MPvJ9i_a5qQCilT1tWXwAKE_fkVGi31_un3OxHbNm9UmMemRp7IZ9C9ZLU4IjMApxVJOWXMYqjt588z_ZVcYG2dtY6Dh0b4R1aAQcp0UXFTggdWtsjPw7wIC
then you will get captcha, but is is not what i want , because javascript everytime changes the capthca image. so i dont get captcha which is currently being shown in webbrowser
You can copy the image to the clipboard and read from there. Alternatively you can parse the page to get the image's URL and see if you can dig the image file out of the cache
How To Programmatically Copy an IMG Element to the Clipboard
Would it be possible to use reCaptcha.net instead? You register for free, add the script to your page and then they do the rest. They may not have zooming for the visually impaired, but they do have text-to-speech. No sense in reinventing the wheel if you don't have to. Of course you'd need access to the internet on your page so this could be a problem if your site is an intranet or private network of some sort. Hope that helps.