Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide view source

Tags:

c#

asp.net

Could some one please help me out to hide a view source option of a web page in dot net ?

like image 946
Vijay Karamchandani Avatar asked May 23 '26 12:05

Vijay Karamchandani


2 Answers

You can't, it is an option of the browser. The best you can do is obfuscate it.

like image 183
Yuriy Faktorovich Avatar answered May 25 '26 02:05

Yuriy Faktorovich


Back in the Geocities era of the internet it wasn't uncommon for sites to use javascript to capture right clicks and popup a message box saying that you weren't allowed to view the source (or save an image or something).

This isn't quite so common nowadays for three main reasons:

  1. It was futile. Preventing someone from using right click to view the source did nothing, as there are plenty of other ways to get at it. It was a minor inconvenience at best. If the browser can render the HTML, the user can get at it too.
  2. It was annoying. Not just the modal message box whenever you accidentally right clicked. Arbitrarily removing functionality from the user's browser is a no-no.
  3. It serves no purpose. If there is some reason that you really don't want the user to see the source of the website then there is something really wrong. If you are doing it to hide how bad the code is, fear not, terribly awful code makes it to production all the time. If you're doing it out of security then this is a majorly bad decision. Security through obscurity (on its own) is never the right choce.

That said, there are ways of obfuscating the code such that the browser can still parse it, but that it is at least annoying for a human to do so. You can use javascript to write certain parts of the page (a la AJAX) such that viewing the vanilla source code doesn't show what it actually rendered. Or you can compress it removing all formatting and naming elements (once it goes to production) such that it is at the very least annoying to follow.

like image 36
Reese Moore Avatar answered May 25 '26 01:05

Reese Moore