I am using ASP.NET C# and in my viewsAll.cshtml i have a JavaScript
that detect if the user is using Internet Explorer or not.
the alert("Other Browser"); or the alert("Internet Explorer"); is working fine.
The Problem is both c# code lines will be executet:
@{ Session["BrowserName"] = "IE";} and @{Session["BrowserName"] = "other";}
but in case of i am using Internet Explore it should only execute
@{ Session["BrowserName"] = "IE";}
viewsAll.cshtml:
<script>
var usera = window.navigator.userAgent;
var ie = usera.indexOf("IE ");
if(ie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
{
alert("Internet Explorer");
$('head').append('<link href="@Url.Content("~")Content/Styles/styleForIE.css" rel="stylesheet" />');
@{ Session["BrowserName"] = "IE";}
}
else{ // If Other Browser
alert("Other Browser");
$('head').append('<link href="@Url.Content("~")Content/Styles/styleForOther.css" rel="stylesheet" />');
@{Session["BrowserName"] = "other";}
}
</script>