Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Dear sir,

How to write a code for disabling view source from mouse right click and choose menu item in menu?

 
in my asp.net page.
Please give me a code.
 
by mohan.
Posted 13-Mar-12 22:35pm
Comments
manoj kumar choubey at 30-Apr-14 8:15am
   
please explain exact requirement to disable view source ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Besides diabling right click ,if you want to stop users from using menu item ,
use a popup frame. There you are unable to use menu item....
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi mohan,
Every browser has its built-in functionality to view the source code or the webpage. We can do one thing. That is disabling right click in your page.
 
For disable right click use the following code:
 
<SCRIPT TYPE="text/javascript">
function disableselect(e){
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</SCRIPT>
 

Remember one thing. We can view this source using firebug or some other third party tools. So we cant do this 100%.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

You can develop your website using Silverlight.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

As mentioned by Shivapragasam, it's not worth doing this - you can always use web developer tools such as firebug to view everything you want about a page.
 
All you're going to achieve by disabling right mouse is annoying anyone using your pages, in case they want to use some context menu items.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Technically, you can't. The client has to receive the HTML to display it. You can try to hide it using frames, but some browsers offer the option to view frame source. Also, a savvy user will know how to get at the source even if you use frames.
 
But as per your need you can do the following:
 
1. Build the page with Flash.
 
2. Build the page entirely with javascript in a .js file and then call the .js file from your HTML.
 
Hope it Helps Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

you cant do it ... Frown | :(
but you can hide context menus using
<body  öncontextmenu="return false">
...
</body>
and frustrate the user.. Wink | ;) )
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 9

my friend if you are using asp.net then many of the code are dynamically created by server on basis of your code.
you dnt need to hide your code becoz in every other process of your page source code will automatiaclly gets changed and by any mean you cannot hide hide source code any buddie can see source code by just go in chrome browser -> setting -> tools -> Developer tools(crtl + shift + i).
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 10

Just, don't do it.
 
No matter what you do, you can't prevent users from having full access to every bit of data on your website. Any Javascript you code can be rendered moot by simply turning off Javascript on the browser (or using a plugin like NoScript). Additionally, there's no way to disable the ability of any user to simply "view source" or "view page info" (or use wget) for your site.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 245
1 OriginalGriff 210
2 Manfred R. Bihy 190
3 CHill60 180
4 _Amy 155
0 OriginalGriff 7,445
1 Sergey Alexandrovich Kryukov 6,157
2 Maciej Los 3,774
3 Peter Leow 3,448
4 CHill60 2,702


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 30 Apr 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100