In normal asp.net the following works:
private float getInternetExplorerVersion()
{
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
float rv = -1;
System.Web.HttpBrowserCapabilities browser = Request.Browser;
if (browser.Browser == "IE")
rv = (float)(browser.MajorVersion + browser.MinorVersion);
return rv;
}
but in asp.net mvc2 gives error at "System.Web.HttpBrowserCapabilities browser = Request.Browser;":
Cannot implicitly convert type 'System.Web.HttpBrowserCapabilitiesBase' to 'System.Web.HttpBrowserCapabilities'
Thanks Arnab
That's because the Browser property is of type HttpBrowserCapabilitiesBase instead of HttpBrowserCapabilities. So either use implicit var or specify the proper type:
float rv = -1;
var browser = Request.Browser;
if (browser.Browser == "IE")
rv = (float)(browser.MajorVersion + browser.MinorVersion);
or if you prefer typing lots of code:
float rv = -1;
System.Web.HttpBrowserCapabilitiesBase browser = Request.Browser;
if (browser.Browser == "IE")
rv = (float)(browser.MajorVersion + browser.MinorVersion);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With