1
I am working on a Vb.net MVC system and need to detect the browser and version.
I will only use Chrome, and IE9+. I was wondering if I could simplify the verification structure using Regex.
Below the section I use to make the check.
If (Not Request.Browser.ToString().ToLower().Contains("ie") And
Not Request.Browser.ToString().ToLower().Contains("internet explorer") And
Not Request.Browser.ToString().ToLower().Contains("chrome")) Then
Return View("IncompativelAgent")
Else
If Not Request.Browser.ToString().ToLower().Contains("chrome") And Request.Browser.MajorVersion < 9 Then
Return View("IncompativelAgent")
End If
End If
I find it very inelegant the way it is.
You can create methods for this and return TRUE or FALSE.
– PauloHDSousa
the issue is not the encapsulation but how to do the regex check to avoid these Ifs.
– RBoschini
Related : http://answall.com/questions/46871/identificar-browser-e-sua-vers%C3%A3o only changes language.
– Guilherme Lautert
William, does not answer, the codifo came to be bigger than mine, I think that if it is not for regex, I can hardly reduce it.
– RBoschini
My algorithm works and is running well, I wanted to simplify this stretch of Ifs
– RBoschini