Click here to Skip to main content
14,884,024 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
how can i disable view source in browsers in asp.net please any one help me...............
Posted
Comments
soni uma 18-Feb-11 7:46am
   
Don't wast time on it. You can not do it.
Rupa1 18-Feb-11 7:47am
   
we have requirement sir
soni uma 18-Feb-11 8:00am
   
Dear this is not possible. You can some how hide your source code. Like data display in any click or data display after page loading. But you can not disable it. Another thing is it is browser functionality.
Rupa1 18-Feb-11 8:02am
   
Ok sir got it

XML
That's not exactly an ASP.NET question, but I'll try to answer. First, you have to know that there is no way you can absolutely protect the source of your page. Any determined hacker will be able to get to it no matter what you do. If the browser can access it to render it, anyone can do it.

To disable the right click button, you just need to handle the onmousedown event:

<body onmousedown="if((event.button|2)!=0){alert('Right button disabled');}">

   
You can't, it's impossible. It's nothing to do with ASP.Net.

Your servers send a response back to the client that made the request (e.g. the web browser), it's the job of the browser to interpret and render the HTML.

It's not just a case of 'view source'

Think about all the web developer plugins for Firefox (i.e Firebug) and the built in tools to Chrome + IE that let you view every aspect of the page.

They break your page down into individual components (images, css, scripts, etc) and the end user can see everything about your page! You can't disable these.

So, no is the short answer. Doesn't matter if you have a requirement or not,
   
Comments
soni uma 18-Feb-11 7:58am
   
Yes you are right Dylan. I had told him that we can not do it.
m@dhu 18-Feb-11 8:01am
   
Good one.
   
That's correct, 5.
Howewer...
"no is the short answer" is seeding doubt. Simple "no" would do.
Be logical, at the moment when restriction is required to be apply, full reply from the server is already downloaded to the client's machine.

--SA
It's wonderful that questions like this are repeated; see this discussion:
how can hide css file and javascript file from aspx page in asp.net[^].

OP wanted to hide CSS and Javascript, but this is the same thing.

—SA
   
You cannot do that but mostly you can restrict the users by disabling the keys and mouse clicks
Check this[^]
   
Comments
   
If this is a joke (both this post and the references article), then it is not very funny.
This is a good example of complete waste of time for destructive, not just useless activity, something that never should be done.
--SA
   
Needless to say, this stupid trick will no way prevent a knowledgeable user from reading the source code; as to not knowledgeable users, they hardly need this code.
Denno.Secqtinstien 21-Nov-11 9:10am
   
all right and hand off to all but i have seen on mozilla website that they had redirected the same page on view source which user was trying to open for code ?? how it can be done ca nany one tell me ?
You can't, it's impossible.
but you can use css and javascript for disable right click
its prevent bigner to view source page
   

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900