如何停止将 .inc 重命名为 .asp 包含可从 Internet 浏览的文件
这样,我就有了一个ASP经典网站。我有很多包含文件,大部分是静态 html,但仍然有一些脚本代码。当它们具有 .inc 扩展名时,Visual studio 2010 将它们显示为纯文本。它们不显示任何语法突出显示或智能感知。所以我将它们重命名为 .asp 扩展名。现在我意识到公众和搜索机器人可以浏览到这些文件并直接执行它们。
有没有办法阻止这种情况,而不需要将文件重命名回 *.inc?
出于多种原因,我不想再提及他们的名字。
- 语法突出显示使代码更具可读性,
- 我不想因重命名而冒任何版本控制问题的风险,我过去曾遇到过这种情况,
- 我只是不想更改引用包含的 100 多个页面
So, I have a ASP classic 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前尚不完全清楚您希望以哪种方式命名文件,因此我将尝试涵盖这两个选项。
如果它们是 .asp 并且显示代码,则意味着 IIS 未正确执行 ASP,请检查您的文件处理程序(让我知道您正在使用哪个 IIS 版本,我会给您说明)。 VS 2010 对经典 ASP 的支持不太好,着色很差并且没有代码补全。如果您有 VS 2008,请使用它,或者您可以获得Eclipse 插件,或者我最近发现Sublime Text 支持经典 ASP,并且在文本着色方面比 VS2010 做得更好(或者如果你有钱的话,有很好的 ol' Dreamweaver)。
如果所有文件都是 .inc,则需要告诉 IIS 使用 ASP 处理程序执行 *.inc。这样,如果有人确实浏览了这些文件,它们将首先被执行,并且不会向浏览器显示任何 asp 代码(它们可能会出错,但这是另一回事)。您的 IDE 不会将 .inc 识别为经典 ASP 扩展名,因此您必须将 .inc 作为 VBScript 添加到您的 IDE 中。再次强调,VS 2010 不太适合经典 ASP,所以当您选择一个 IDE 时,请告诉我,我将设置一些有关更改其中文件关联的说明。
文件关联:
VS2010
工具>选项>文本编辑器>文件扩展名
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
使用不同的编辑器(例如 Notepad++),它允许您手动设置语言编码。
Use a different editor like Notepad++ that allows you to manually set the language encoding.