Is there an effective method for identifying the user's browser and preventing them from accessing the page?

Hey there! I'm looking to restrict user access to my page only if they are using Chrome or IE8-9. I've implemented this restriction in the code behind, as shown below, and attempted to hide the main div element.

 protected void Page_Load(object sender, EventArgs e)
    {
        System.Web.HttpBrowserCapabilities browser = Request.Browser;
        if (browser.Type.ToString().ToLower().StartsWith("ie"))
        {
            if (Convert.ToDecimal(browser.Version) < 8 || Convert.ToDecimal(browser.Version) > 9)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "pop", "<script>alert('Your browser is not supported. Please use Chrome or IE7,IE8,IE9');</script>", false);
                pagecontainer.Attributes["style"] = "visible:none";
                return;
            }
        }
        else if (!browser.Type.ToString().ToLower().StartsWith("chrome"))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "pop", "<script>alert('Your browser is not supported. Please use Chrome or IE7,IE8,IE9');}</script>", false);
            pagecontainer.Attributes["style"] = "visible:none";
            return;
        }
//blah blah       
}


<div id="pagecontainer" runat="server" >Page Content Goes Here</div>

However, it seems that the div is not being hidden as intended. While I could redirect users to a warning page, I'd prefer to explore alternatives. Any suggestions?

Answer №1

Delete the following line:

pagecontainer.Attributes["style"] = "visible:none";

Replace it with this line:

pagecontainer.Attributes.Add("style", "display:none;");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unexpected focus on bootstrap button data-toggle is causing issues

What is the reason for adding the .focus class to the style of the button? This seems to be preventing the appearance of the button from changing. I found this code on the Bootstrap site, where only the .active class is being toggled, not .focus. <but ...

Enhancing speed and efficiency through the utilization of Three.js

I'm currently working on my first Three.js / WebGL application, and while it runs smoothly on my PC (Chrome), I've noticed that the framerate tends to drop below 30 frames per second on other PCs. Despite the application not being overly complex ...

In this context, 'number' is typically a data type, but it seems to be functioning as a specific value

Greetings! I'm encountering an issue with this Angular 4 code. Whenever I attempt to type a number, I encounter the following error: 'number' only refers to a type, but is being used as a value here.ts(2693). View image description here ...

The function `$('body').on('blur')` is having issues in Internet Explorer 8

How can I fire a function when $('body').on('blur') occurs? This code works perfectly in all browsers except for IE8 $(document).ready(function () { $(window).focus(); $(window).on("focus", function () { ...

Creating an eye-catching display with Bootstrap 4: Achieving a row of cards with varying heights

Is there a way to set up two cards next to each other in a row without one resizing to match the other? Whenever I resize the page, the cards no longer stay adjacent and collapse onto separate rows with different sizes. Manually setting the height works, b ...

Having trouble downloading a PDF file on a local server with React and the anchor tag element

Having trouble downloading a pdf file from my react app to my Desktop. I've reached out for help with the details How to download pdf file with React. Received an answer, but still struggling to implement it. If anyone new could provide insight, that ...

Oops! TypeScript error TS2740: The type 'DeepPartial<Quiz>[]' is currently missing key properties from type 'Question': id, question, hasId, save, and a few more

I'm struggling to resolve this error. Can anyone provide guidance on what needs to be corrected in order for this code to function properly? import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm& ...

I seem to be having trouble getting my style to work properly with Material UI's makeStyles

I am experiencing an issue with Material-UI makeStyles not working properly. I am trying to apply my CSS style but it doesn't seem to be taking effect. I suspect that Bootstrap or MaterialTable might be causing this problem. While Bootstrap4 works fin ...

Merging two separate rows into one in Bootstrap 4

I have a layout with 2 rows, each row consisting of 3 columns. Each column is assigned the classes .col-lg-4 .col-md-4 .col-sm-12. I am looking to combine two vertically aligned columns (the one containing the image and the one above) into a single column. ...

Transferring a PHP variable to a different PHP script through AJAX

I am facing an issue with displaying data stored in a MySQL table inside div elements. Each div with the class content-full is created based on the data in the database. However, when I click on any of these divs, the content associated with the last div i ...

What is the approach for obtaining the specified arrays using two pointer methodology in JavaScript?

input [1,8,9] output [[1],[1,8],[1,8,9],[8],[8,9],[9]] It appears to be a subset array, but I am aiming to achieve this output using a two-pointer approach. Let's assign leftP=0, rightP=0; and then utilizing a for loop, the rightP will iterate until ...

Injecting values into ASP.NET MVC ActionFilterAttribute before model binding takes place

Is it possible to create a custom action filter attribute that can add a value in the HttpContext items for accessibility during model binding? I attempted to add it in the OnActionExecuting method, but it seems that model binding is executed before the f ...

"Utilize JavaScript to detect both the loading and unloading events on a webpage

I attempted to capture the window.open onload and onunload events. The issue arises when I use URLs from other domains. For example: When the URL is for the same page, both events trigger as desired. window.open("/") View PLUNKER with same page URL .. ...

How can I redirect to another page when an item is clicked in AngularJS?

Here is an example of HTML code: <div class="item" data-url="link"></div> <div class="item" data-url="link"></div> <div class="item" data-url="link"></div> In jQuery, I can do the following: $('.item').click ...

Exploring various views in localhost with HTML using AngularJS in asp.net (No MVC)

How do I configure URLs in ASP.NET for AngularJS routing? I've been experimenting with various online examples, but so far I've only managed to get the default route ('/') to display the correct view. It seems like a URL configuration ...

What is the best way to ensure a table cell remains fixed to the top and left side of the table simultaneously?

My table with a sticky header is giving me trouble. I initially set the position property as position:sticky; top:0;, and then tried to overwrite it for the first column using position:sticky; **left:0**;. However, the heading of column 1 remains sticky on ...

Contrast between legacy and modern variables within angular

Trying to compare an old value in a <td> with the new value entered by the end user. Using ng-blur to detect when there is focus out of the field rather than calling the function, but the simple logic doesn't work. This table structure: <ma ...

What is the best way to attach an image to the image section coming from the backend in vue.js?

I have developed a frontend page that displays a list of books, with the data coming from the backend. The backend response includes image files, and I am struggling to bind these images to the image section of my template. I have the image paths from the ...

Exploring the Angular Heroes tutorial with the unique app-heroes CSS selector

While going through the Angular tutorial at https://angular.io/tutorial/toh-pt1#selector, one particular sentence caught my attention: "The CSS element selector, 'app-heroes', matches the name of the HTML element that identifies this component wi ...

Looking for guidance on implementing the Passport authentication strategy within an Express application?

If I have a script similar to this one, which utilizes a Passport authentication strategy with an Express backend, how can I implement API function calls using this script? I am unable to find any direct examples in the documentation of the project linke ...