The best browser detection solution in ASP.NET 4.0 - asp.net

I googled this topic and I came across with three different ways to configure browser capabilities: browscap.ini, browserCaps element in web.config and .browser files in App_Browsers. I thought .browser files is the latest way, but I don't seem to find up-to-date files. But I found quite fresh browscap.ini from http://browsers.garykeith.com/downloads.asp.
My first priority is to exclude common crawlers from the visitor stats. The second priority is to detect browser and os with correct versions (e.g. Opera 11 / Win7).
Are there any libraries I could use? Is browscap.ini still a valid way and is it possible to use it without access to system files? Where can I find up-to-date .browser files?

more info : http://msdn.microsoft.com/en-us/library/3yekbd5b.aspx
Have you checked this :
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "\n";
TextBox1.Text = s;

I found a user agent parser from http://user-agent-string.info/ and it seems to be good enough for my purposes.

Just so no one else goes down that dark path, be aware that even the jQuery team recommend that you DO NOT use jQuery.browser object:
"The $.browser property is deprecated in jQuery 1.3"

The best answer is feature detection, not browser detection! This is particularly true in the day where Firefox & Chrome are putting out releases ever few months and mobile browser use is growing. Use Modernizr (http://Modernizr.com) or an equivalent library to detect the features you are interested in.

So far I've used http://api.jquery.com/jQuery.browser/ for client side detection.

Related

Getting image from an online XML file or a URL in xamarin forms

I am unable to get image from a URL that is an XML response. i used following code to fetch information from this URL including image too since i thought that i will get image although the xml response has image url but i am getting image URL instead of image.
Why is it so? kindly guide me! i am a newbie to xamarin forms.
URl : https://www.goodreads.com/book/title.xml?key=Uxb0zPb86N4STVy2ECWYA&title=Dune
CODE:
XElement search_result =(from xFi in Xdoc.Descendants("book")
where (xFi.Element("country_code").Value == "PK") || (xFi.Element("language_code").Value == "eng")
select xFi).FirstOrDefault();
if (search_result != null)
{ search.Text=
"Title: " + search_result.Element("title").Value + "\n" +
"Average Ratings: " + search_result.Element("average_rating").Value + "\n" +
"ISBN: " + search_result.Element("isbn").Value + "\n" +
"PUBLICATION YEAR: " + search_result.Element("publication_year").Value +
"\n" +"PUBLISHER: " + search_result.Element("publisher").Value + "\n" +
"DESCRIPTION: " + "\n" + search_result.Element("description").Value + "\n"
+ "IMAGE: " + "\n" + search_result.Element("image_url").Value + "\n";
} else
{
search.Text = "Found Nothing";
}
assuming I have an Image control on my page named "bookimage"
var url = search_result.Element("image_url").Value;
bookimage.Source = ImageSource.FromUri(new Uri(url));
this is clearly explained in the docs

Tag type as string variable in selenium

How to pass tag type as a string variable in selenium?
suppose I am having given example:
By.cssSelector: li[__idx='0']
for given example I tried below part
webElement.findElement( By.cssSelector( "'" + tag + "'['" + property + "'='" + indexNumber + "']" ) )
where tag is li and __idx is property.
I am getting error as " Could not locate element with locator ". but if I tried as below then its working correctly.
webElement.getElement().findElement( By.cssSelector( "li[__idx='" + indexNumber + "']" ) )
Is there any syntactical mistake am doing ?
webElement.find( "" + tag + "[" + property + "='" + indexNumber + "']" );
This is the correct way to solve the issue.

How to find which properties in the .theme file are used to generate a given CSS class in GXT3?

Current Sencha documentation about their Theme Builder is very limited, it covers only the file basic structure and the syntax (including gradients and functions):
http://docs.sencha.com/gxt/3.1/ui/theme/syntax/ThemeBuilderSyntax.html
My problem is which property should I set in the .theme file in order to affect an specific CSS class? For example the font used in the header of a ContentPanel.
First thing I tried was to have a look in the file themebuilder\examples\skeleton-config\skeleton-config.theme which is supposed to have "all required properties", but I could not find any "contentPanel" in it.
This is the example they have in the documentation:
details {
info {
messageText = defaultFont
//note that this could also be written as
//messageText = theme.defaultFont
}
}
In this case it is straightforward because there is an Info class which matches the "info" element used in the theme.
Then I had a look in the generated HTML and found this CSS class name in the header of my ContentPanel:
.CS-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerText
By looking at this class name I thought the element name to be used in the .theme file would be "panel" and the property name would be "headerText", but unfortunately checking the file skeleton-config.theme I saw there is no headerText property in the panel element.
I have found headerText in other elements like datePicker, errortip, info and tip, so it is funny that panel does not have it.
The way I have found to know exactly which configuration parameter I have to set in order to affect an specific CSS was to have a look at the GWT generated classes.
I started by checking the generated HTML and there I found the CSS class name:
.CS-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerText
Then I searched for this string in the directory target/.generated (I am using Maven) and found the class Css3HeaderAppearance_Css3HeaderResources_default_InlineClientBundleGenerator.java where that string appeared many times:
".CS-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerText {\n right : " + ("20px") + ";\n}\n" +
".CS-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerText {\n font-family : " + ("tahoma"+ ","+ " " +"arial"+ ","+ " " +"verdana"+ ","+ " " +"sans-serif") + ";\n font-size : " + ("11px") + ";\n font-weight : " + ("bold") + ";\n line-height : " + ("15px") + ";\n color : ") + ((theme().panel().font().color() + "") + ";\n font-size : " + (theme().panel().font().size() + "") + ";\n font-weight : " + (theme().panel().font().weight() + "") + ";\n font-family : " + (theme().panel().font().family() + "") + ";\n line-height : " + ("15px") + ";\n text-transform : " + ("none") + ";\n}\n.PR-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerBar {\n float : " + ("left") + ";\n}\n/* CssDef */\n/* CssDef */\n/* CssDef */\n/* CssDef */\n")) : ((".OR-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-header {\n padding : " + ("4px"+ " " +"3px"+ " " +"2px"+ " " +"5px") + ";\n position : " + ("relative") + ";\n padding : " + ("0") + ";\n}\n.BS-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerIcon {\n float : " + ("left") + ";\n}\n.AS-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerHasIcon .BS-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerIcon {\n width : " + ("18px") + ";\n}\n.AS-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerHasIcon " +
".CS-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerText {\n left : " + ("20px") + ";\n}\n" +
".CS-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerText {\n font-family : " + ("tahoma"+ ","+ " " +"arial"+ ","+ " " +"verdana"+ ","+ " " +
"sans-serif") + ";\n font-size : " + ("11px") + ";\n font-weight : " + ("bold") + ";\n line-height : " + ("15px") +
";\n color : ") + ((theme().panel().font().color() + "") + ";\n font-size : " + (theme().panel().font().size() + "") + ";\n " +
"font-weight : " + (theme().panel().font().weight() + "") + ";\n font-family : " + (theme().panel().font().family() + "") + ";\n line-height : " + ("15px") + ";\n text-transform : " + ("none") + ";\n}\n.PR-com-example-client-base-panel-Css3HeaderAppearance-Css3HeaderStyle-headerBar {\n float : " + ("right") + ";\n}\n/* CssDef */\n/* CssDef */\n/* CssDef */\n/* CssDef */\n"));
I have noticed that it first generates some hard-coded CSS classes and at the end it generated a CSS class based on the values returned by calls to theme().*.
Finally, by comparing these calls with the structure of the file skeleton-config.theme I had the answer to my question:
theme() maps to the "details" element in the .theme file
theme().panel() maps to details.panel or
details {
panel {
so the configuration I had to use was the font property inside the panel element.
This answers my first question, but it does not clarify what are all widgets affected by the "panel" element in the .theme file.

html.partial with dynamic append using script (Razor)

trying to do the below
$('#body').append('<div id=\"'+ name + 'div\"' + '>' + '\'' + #Html.Partial("_ChatWindow") + '\'' + '</div>');
_chatwindow.cshtml is just
<button>test</button>
but i get a run time syntax error at the opening angle bracket of the partial class. Any suggestions?
You need to create a string for partial view content:
$('#body').append('<div id=\"'+ name + 'div\"' + '>' + '\'' + '#Html.Partial("_ChatWindow")' + '\'' + '</div>');

Get product version of DLLs

Trying to get the "Product Version" attribute from loaded DLLs.
For example, my System.Web.dll has a product version of 2.0.50727.4955 if you click File > Properties from explorer.
However I have the following code:
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in assemblies)
{
stringBuilder.Append("<br/>");
stringBuilder.Append("<div><b>Name: </b>" + assembly.GetName() + "</div>");
stringBuilder.Append("<div><b>Full name: </b>" + assembly.FullName + "</div>");
stringBuilder.Append("<div><b>Is from GAC: </b>" + assembly.GlobalAssemblyCache + "</div>");
stringBuilder.Append("<div><b>ImageRuntimeVersion: </b>" + assembly.ImageRuntimeVersion + "</div>");
}
The ImageRuntimeVersion returns v2.0.50727, is there any way I can get the last 4 digits of the product version also?
Thanks!
You're looking for the FileVersionInfo class:
FileVersionInfo.GetVersionInfo(typeof(string).Assembly.Location)
I usually do something like this, which does return the last portion of the version:
return Assembly.GetAssembly(typeof(System.Web.UI.ScriptManager)).GetName().Version.ToString();

Resources