Reputation: 2354
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
Upvotes: 3
Views: 2986
Reputation: 1038810
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);
Upvotes: 6