قطعه کد زیر در برنامههای ASP.NET، نام مرورگر کاربر و همچنین شماره نگارش آنرا باز میگرداند:
var browser = Request.Browser.Browser + " " + Request.Browser.Version;
برای مثال با فایرفاکس، چنین خروجی را دارد:
اما ... با مرورگر جدید Edge مایکروسافت، خروجی کروم را مشاهده خواهیم کرد:
از این جهت که user agent این مرورگر، چنین شکلی را دارد و ختم به edge است:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240
برای رفع این مشکل، نیاز است فایل جدیدی را به مجموعهی «browser definition files» دات نت اضافه کنیم. این فایلها عموما در مسیر زیر یافت میشوند:
<windir>\Microsoft.NET\Framework\<ver>\CONFIG\Browsers
برای نمونه مسیر ذیل را برای مشاهدهی فایلهای مرورگرهای موجود، بررسی کنید:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\Browsers
در این بین اثری از تعریف مرورگر edge نیست. برای حل این مشکل، الزاما نیازی نیست تا فایل مرورگر جدیدی را به پوشهی فوق اضافه کنیم. میتوان تعریف این فایل را در پوشهی استانداردی به نام App_Browsers نیز در ریشهی پروژه، قرار داد:
با این محتویات:
<browsers>
<browser id="Edge" parentID="Chrome">
<identification>
<userAgent match="Edge/(?'version'(?'major'\d+)(?'minor'\.\d+))" />
</identification>
<capabilities>
<capability name="browser" value="Edge" />
<capability name="version" value="${version}" />
<capability name="majorversion" value="${major}" />
<capability name="minorversion" value="${minor}" />
</capabilities>
</browser>
</browsers>
در اینجا user agent مرورگر کاربر دریافت شده و اگر ختم به Edge بود، نام و شماره نگارش صحیح آن، دریافت خواهد شد.
اکنون پس از این تنظیمات، برنامه (تفاوتی نمیکند که وب فرم باشد یا MVC) اطلاعات صحیحی را نمایش میدهد: