views:

55

answers:

2

I have a masterpage on which i want to check if user have disabled its javascript then redirect to a simple error.aspx page

+4  A: 

The usual way to approach this problem is to redirect a user who has javascript enabled and display the error for the user who has it disabled using the noscript tag.

 <script type="text/javascript">
     location.href = 'pagethatneedsjavascript.aspx';
 </script>
 <noscript>
     This page needs JavaScript enabled!
 </noscript>

Alternatively if your page isn't the first page the user would load in the current session, you could add a link to the page like

<a href="/linktopage.aspx?js=disabled"
onclick="location.href='/linktopage.aspx?js=enabled';return false;">the page</a>

If the user has javascript disabled, they'll go to the page referenced in the href attribute, if they have it enabled the JavaScript in the onclick attribute will be executed instead.

You can then on the server side read the querystring variable and redirect if it equals "disabled"

if ( Request.QueryString["js"] == "disabled" ) {
    Response.Redirect("error.aspx");
}

Note that if the page is bookmarkable the user might end up on the page using js=enabled without js actually being enabled.

Mario Menger
A: 

On Masterpage just add this code

<noscript>
<% Response.Redirect(Url.Action("ActionName","ControllerName")); %>
</noscript>

If user disabled the javascript it will redirect to specific controller action.

Fraz Sundal