We are seeing some Safari browsers failing to cross-authenticate our website after we upgrade to .NET 4.0 from .NET 3.5.
After much investigation, it turns out to be a problem with ASP.NET identifying the Safari browsers properly. ASP.NET identifies some Safari (possibly other WebKit-based browsers) as Mozilla Version 0.0. browsers that do not support cookies, frames, JavaScript, etc. .NET 3.5 does not have any problems identifying these browsers.
We have simplified testing down to a simple HTTP handler (running on a vanilla 4.0 website) that only returns the browser capabilities of the requestor.
Here are a few User-Agents that fail to be identified (they are identified as Mozilla 0.0):
Mozilla/5.0+(Macintosh;+U;+Intel+Mac+OS+X+10_5_8;+en-us)+AppleWebKit/533.19.4+(KHTML,+like+Gecko)+Version/5.0.3+Safari/533.19.4
Mozilla/5.0+(Macintosh;+U;+Intel+Mac+OS+X+10_6_2;+en-us)+AppleWebKit/531.9+(KHTML,+like+Gecko)
Mozilla/5.0+(Macintosh;+U;+Intel+Mac+OS+X+10_6_7;+en-us)+AppleWebKit/533.20.25+(KHTML,+like+Gecko)+Version/5.0.4+Safari/533.20.27
Mozilla/5.0+(Macintosh;+U;+Intel+Mac+OS+X+10_6_6;+en-us)+AppleWebKit/533.18.1+(KHTML,+like+Gecko)
The handler code looks like this:
<%# WebHandler Language="C#" Class="PowershellTemporaryHandler" %>
using System;
using System.Web;
using System.Web.Security;
public class PowershellTemporaryHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
HttpBrowserCapabilities hbc = context.Request.Browser;
context.Response.Write("Type=" + hbc.Type + "<br>");
context.Response.Write("Name=" + hbc.Browser + "<br>");
context.Response.Write("Version=" + hbc.Version + "<br>");
context.Response.Write("Major Version=" + hbc.MajorVersion + "<br>");
context.Response.Write("Minor Version=" + hbc.MinorVersion + "<br>");
context.Response.Write("Platform=" + hbc.Platform + "<br>");
context.Response.Write("Is Beta=" + hbc.Beta + "<br>");
context.Response.Write("Is Crawler=" + hbc.Crawler + "<br>");
context.Response.Write("Is AOL=" + hbc.AOL + "<br>");
context.Response.Write("Is Win16=" + hbc.Win16 + "<br>");
context.Response.Write("Is Win32=" + hbc.Win32 + "<br>");
context.Response.Write("Supports Tables=" + hbc.Tables + "<br>");
context.Response.Write("Supports cookies=" + hbc.Cookies + "<br>");
context.Response.Write("Supports VBScript=" + hbc.VBScript + "<br>");
context.Response.Write("Supports Frames=" + hbc.Frames + "<br>");
context.Response.Write("Supports JavaScript=" + hbc.EcmaScriptVersion.ToString() + "<br>");
context.Response.Write("Supports Java Applets=" + hbc.JavaApplets + "<br>");
context.Response.Write("Supports ActiveX Controls=" + hbc.ActiveXControls + "<br>");
context.Response.Write("User Agent=" + context.Request.UserAgent + "<br>");
}
}
We are bewildered as to the lack of mention on the Internet about this problem. It seems that we need to add Browser defintions either to the framework/config/browsers folder or else to the App_Browsers folder at the website level, but it seems bizarre that we would need to tweak Browser definitions for a .NET 4.0 website to run properly.
Does anyone have any experience with this issue?
I have been running into what seems to be a similar issue. It seems that ideed some Safari user agents are not properly recognized and instead reported as Mozilla 0.0, BUT some investigation showed me that this failure is not exactly reproducible. If I use my Firefox's UserAgent-Switcher to send the exact same user agent that previously failed to be recognized and take a look at the browser capabilities, it is correctly reported as a Safari. Going through the server log files (after adding some debug information) also seems to confirm this behavior. The very same client with the very same (Safari) user agent is sometimes recognized correctly and occasionally reported as Mozilla 0.0 - most of the time it is incorrectly recognized a couple of times in a row before it gets it right again... It only seems to affect Safari user agents - if anybody is interested, I have a rather long list, the most recent one being:
|Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; de-de) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5|
Does anybody have more information on this issue?
EDIT 2011-08-24
It seems that I have found the root cause of the problem. The UserAgent -> BrowserCaps resolving mechanism uses a cache to temporarily store mappings. Unfortunately it uses (by default) the first 64 characters of the UserAgent string as cache key and THAT is just BS... Occasionally a user agent pops up that looks like a Safari, but really isn't and that one is not resolved properly (Mozilla 0.0), but the mapping is still stored in the cache, which means that all UserAgent strings with the same 64 character prefix are now incorrectly mapped as well until that cache entry expires (sliding window with 1 minute). The key length used for caching can fortunately be configured with
<browserCaps userAgentCacheKeyLength="..." />
in the config section. I've upped the key length to 256 and since that the problem has disappeared. Now I'll try to figure out which UserAgent string was responsible for the cache poisoning in the firs place - and I'll update this post if I find anything.
Solution
I put the <browserCaps userAgentCacheKeyLength='256'> element under <system.web> and everything appears to work, as follows:
<configuration>
<system.web>
<browserCaps userAgentCacheKeyLength="256" />
</system.web>
</configuration>
Detailed explanation
The 'Browser capabilities user agent cache key length' resolving mechanism uses a cache to temporarily store mappings.
By default it uses the first 64 characters of the UserAgent string as cache key, however when a user agent pops up that looks like it belongs to Safari, but really isn't does not resolve properly i.e. 'Mozilla 0.0'
The mapping is stored in the cache, which means that all UserAgent strings with the same 64 character prefix are now incorrectly mapped until the cache entry expires i.e. usually 1 minute.
The key length used for caching is configured using the following:
Increase the key length to 256 to resolve the problem.
...I had problems finding the correct place in my web.config file to insert the above.
When I inserted the <browserCaps userAgentCacheKeyLength="..." /> element directly under <configuration> in my web.config file, my web-application immediately crashed.
Fortunately, this happened in the test environment and not in production environment.
After searching online, I found an old MSDN / ASP .NET reference page (http://msdn.microsoft.com/en-us/library/sk9az15a%28v=vs.71%29.aspx) that suggested that the <broswerCaps> element is a child of <system.web>.
I tried all answers from this thread, but for the User Agent from the IPhone 4S:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3 like Mac OS X; de-de) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8F190
It still went wrong. Eventually I used the ClientTarget property with the value "uplevel" to force ASP.NET to always enable new browser features. I've put this in a base class that all pages inherit from.
See: http://msdn.microsoft.com/en-us/library/system.web.ui.page.clienttarget.aspx
I highly recommend that you consider leveraging the following:
http://aspnet.codeplex.com/releases/view/41420
Related
I am using VS 2019 to develop core.net web Api. I am trying to read the all methods and Parameters inside my controller. I am using Repository pattern to develop API.
Below is the code from my repository.
var method = MethodBase.GetCurrentMethod();
_log4net.Info("Assembly Name : " + Assembly.GetCallingAssembly().FullName);
_log4net.Info("Method Name : " + method.Name);
_log4net.Info("Repository Name :" + method.ReflectedType.FullName);
var result =
((System.Reflection.TypeInfo)Assembly.GetCallingAssembly().GetTypes().Where(type
=> type.FullName.Contains("AsmeController")).FirstOrDefault()).DeclaredMethods;
_log4net.Info(result);
Log's:
In Debug Mode:
After deployment in IIS
This code is working as expected and returns the list of Method Info in Debug mode and not working and return Null in Release mode even after deployed in IIS.
As i observed using logs, Assembly name was changing Demo.dll to “ Assembly Name : Anonymously Hosted DynamicMethods Assembly “ after deployment.
Please give me suggestions to solve this problem.
For the work around i am directly reading the application dll, Instead of reading current assembly. So that i can able to access the all info from there.
string assemblyFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location + "\\Demo.dll");
Assembly testAssembly = Assembly.LoadFile(assemblyFile);
var result = ((TypeInfo)testAssembly.GetTypes().Where(type => type.FullName.Contains("AsmeController")).FirstOrDefault()).DeclaredMethods;
I'm building an app using React Native.
I'm fetching an array of values fetched from a database in order to provide users a line chart which refresh every X seconds ( 3s atm ).
This works fine on iOS simulator but when it comes to deploy to TestFlight, and run the app on a device, the curves are not displayed, nothing happens.
Since I can use some other feature that requires to fetch data from the DB, I figured out that the issue was not from the API requests.
I currently use react-native-chart-kit, but I tried with react-native-svg-charts as well, the issue remains the same.
Any hint ?
The issue is the same when I display the array of the fetched values, a new value appears on the simulator every 3 seconds but it does not show anything on the device.
I finally found the issue.
The issue were spotted at the API request.
My request takes 2 timestamp params : start time / end time
I always debug the app using the browser and launch ios sim from the RN project.
This time I tried to Run a the project from Xcode and edit the Scheme as release instead of debug .
When I checked the console from Xcode I noticed that my Start time timestamp when considered as 'NaN'.. Not the End time timestamp.
Back to the RN project and to the browser console, the timestamp is alright.
I made some random changes and now it works fine .
Here's what I had before solving the issue:
function formatDate(rawStamp) {
const now = new Date(rawStamp);
var convertToStr =
now.getFullYear() +
"-" +
("00" + (now.getMonth() + 1)).slice(-2) +
"-" +
("00" + now.getDate()).slice(-2) +
" " +
("00" + now.getHours()).slice(-2) +
":" +
("00" + now.getMinutes()).slice(-2) +
":" +
("00" + now.getSeconds()).slice(-2);
return convertToStr
}
const nowStr = formatDate(Date.now() - 7200000)
const gameStampMinusX = Date.parse(nowStr) - (300000)
const gameStampMinusXToStr = formatDate(gameStampMinusX)
Here's what solved the issue:
const nowStr = formatDate(Date.now() - 7200000)
const gameStampMinusX = Date.now() - 7200000 - 300000
const gameStampMinusXToStr = formatDate(gameStampMinusX)
I'm a newbie so I cannot explain this behavior, but seems that this little change makes Xcode recognize the timestamp, and proceed the the API request correctly.
If anyone can explain, feel free !
I use the following command to launch a JS script: C:\Windows\System32\cscript.exe /nologo //E:{16d51579-a30b-4c8b-a276-0ff4dc41e755} in order to use the latest Chakra engine.
In my script, the command WScript.Echo( ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion() + "." + ScriptEngineBuildVersion()); outputs 11.0.19326.
I know this increases performance, and I thought I'd be also able to use the latest XMLHttpRequest instead of the good old Microsoft.XMLHTTP (I need responseURL) but it looks like I am not.
Is there a solution?
My guess is, the way you're loading the Chakra engine it's loading an invisible IE instance. But according to this MDN compatibility table there is no version of Internet Explorer that supports responseURL.
edit: don't use JScript
Through much testing, attempting to load Edge's Chakra engine into Windows Script Host, I can land on no permutation that works. Creating an htmlfile COM object and forcing compatibility using x-ua-compatible, attempting the same with an HTA application (both natively and again with an htmlfile COM object), attempting to create a MSXML2.ServerXMLHTTP.6.0 object, no Windows Script Host hack I can conceive will expose the .responseURL property of an XMLHttpRequest object.
Best bet would be to pick a different language. In PowerShell you could do something like this:
$req = [Net.WebRequest]::Create("https://youtu.be/")
$resp = $req.GetResponse()
$resp.ResponseURI.AbsoluteURI
... which would print
https://www.youtube.com/?feature=youtu.be
And if you need the equivalent of .responseText, just add the following:
$reader = new-object System.IO.StreamReader $resp.GetResponseStream()
$responseText = $reader.ReadToEnd()
If you want to parse $responseText using DOM methods...
$htmlfile = new-object -COM htmlfile
$htmlfile.IHTMLDocument2_writeln($responseText)
$buttons = $htmlfile.getElementsByTagName("button")
You can see the original revision of this answer for an example of what doesn't work.
I move my Selenium installation to a new server, since then some tests using logins no longer work.
After investigation, I found that the password field was populated with an incorrect value. Therefore the tests failed.
I'm trying to do the following :
_passWordTextBox.Clear();
_passWordTextBox.SendKeys("!!ä{dasd$352310!!!\\_XY>èà$£<?^^");
Here is how the field is populated after those lines:
The "!" character was the only one missing. It worked on the previous server. Some other suspicious characters (like $ éà<) also worked.
I've looked at locale settings (culture differences) between the servers.
From these characters sent in a Password string:
!"#$%&'()*+,-./0123456789:;<=>?#ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
All of these worked correctly:
"#$%&'()*+,-./0123456789:;<=>?#ABCDEFGHIJKLMNOPQRSTUVWXYZ[\ _ abcdefghijklmnopqrstuvwxyz{|}
Only these failed to be sent correctly:
!]^`~
I've also tried in other fields (such as a Description field) and see the same failure.
I've tried to see if the command was sent correctly to the selenium server, but the logs seem to suggest it worked:
08:05:35.850 DEBUG [ReverseProxyHandler.execute] - To upstream: {"value":["!\"#$%&'()*+,-./0123456789:;<=>?#ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~?"]}
It means that the server receives the command correctly, but for some reason the driver or the server doesn't execute properly.
Try this:
_passWordTextBox.SendKeys(#"!!ä{dasd$352310!!!\\_XY>èà$£<?^^");
Maybe is for the validates from field.
You can try using clipboard:
public static void SendValueFromClipboard(this IWebElement txtField, string value)
{
Clipboard.SetText(value);
txtField.SendKeys(OpenQA.Selenium.Keys.Control + "v");
}
This is written on C#, you will need to rewrite it in language, you are using.
After looking into multiple system settings i discovered that both my piloting and executing machine add the same regional settings (Format : French(Switzerland) , Keyboard : French(Switzerland), and I didn't look any further.
While fiddling around i discovered this setting :
As it turns out , the Language for non-Unicode programs was set to French(Switzerland) on the machine executing the tests. Changing it to English(UK) resolved the problem.
Probably a bug in chromedriver.
Your solution doesn't work for me, since I already have that setting set to English, but here's a solution I found if anyone else's interested.
Just change your keyboard to ENG UK in task bar.
Is there any limit to the number of characters for the file name to get it render from phantomJs?
var page = require('webpage').create();
page.open('http://github.com/', function() {
window.setTimeout(function(){
var filename = encodeURI('The code shown here is also available in various examples included with PhantomJS. You are also recommended to explore the use of PhantomJS for page automation, network monitoring, screen capture, and headless testing The code shown here is also available in various examples included with PhantomJS. You are also recommended to explore the use of PhantomJS for page automation, network monitoring, screen capture, and headless testing');
console.log('filename: ' + filename);
page.render(filename + ".png");
phantom.exit();}, 100);
});
This file is not getting render through phantomJs.
Can someone please help here?
I don't think it has anything to do with PhantomJS, but basically with your OS. There is a size limit for the file path name in every OS.
According to the naming convention in Windos OS -
In the Windows API (with some exceptions discussed in the following
paragraphs), the maximum length for a path is MAX_PATH, which is
defined as 260 characters. A local path is structured in the following
order: drive letter, colon, backslash, name components separated by
backslashes, and a terminating null character. For example, the
maximum path on drive D is "D:\some 256-character path string"
where "" represents the invisible terminating null character for
the current system codepage. (The characters < > are used here for
visual clarity and cannot be part of a valid path string.)