How to stop renamed .inc to .asp includes files to be browseable from the internet
So, I have a ASP classi开发者_高级运维c website. I had many includes files that were mostly static html, but still some script code. When they have a .inc extension Visual studio 2010 shows them as plain text. They do not show any syntax highlighting or intellisense. So I renamed them to .asp extensions. Now I've realized that the public and search bots can browse to those files and execute them directly.
Is there a way to stop this without needing to rename the files back to *.inc?
I don't want to name them back for several reasons.
- The syntax highlighting makes code so much more readable
- I don't want to risk any issues with version control from renaming, which I've had in the past
- I just plain don't want to have to change 100+ pages that reference the includes
It's not entirely clear which way round you want the files to be named so I will try and cover both options.
If they are .asp and they are showing the code, it means IIS is not executing the ASP properly, check your file handlers (let me know which IIS version you are using and i'll get you instructions). VS 2010 doesn't support classic ASP very well, the colouring is poor and there is no code completion. Use VS 2008 if you have it or you can get an Eclipse plugin, or I recently found Sublime Text that supports Classic ASP and does a much better job of colouring the text that VS2010 does (or there's good ol' Dreamweaver if you have money to burn).
If all your files are .inc, you will need to tell IIS to execute *.inc with the ASP handler. This way if someone did browse to the files, they would be executed first and not show any asp code back to the browser (they'll probably error, but that's a different matter). Your IDEs won't recognise .inc as a Classic ASP extension, so you will have to add .inc as being VBScript to your IDE. Again, VS 2010 isn't great for Classic ASP, so when you've picked an IDE that is, let me know and I'll set some instructions on changing file associations within it.!
File Associations:
VS2010
Tools > Options > Text Editor > File Extension
Use a different editor like Notepad++ that allows you to manually set the language encoding.
精彩评论