简体   繁体   English

防止绕过ASP.NET缩小

[英]Prevent circumventing ASP.NET minification

I've got some ASP.NET that I'm deploying as an Azure cloud service. 我已经将一些ASP.NET部署为Azure云服务。 The javascript files have comments in them that I'd like not to be visible to anyone consuming the JS. javascript文件中有注释,我想让使用JS的任何人都看不到它们。 I'm taking advantage of ASP.NET bundling and minification: 我利用ASP.NET捆绑和缩小的优势:

http://www.asp.net/mvc/overview/performance/bundling-and-minification http://www.asp.net/mvc/overview/performance/bundling-and-minification

This seems to be a nice solution in that it removes all comments during the minifcation process. 这似乎是一个不错的解决方案,因为它会在最小化过程中删除所有注释。 But I can't count on the fact that the user won't directly point his or her browser directly to the individual, original js files. 但是我不能指望用户不会直接将其浏览器直接指向各个原始js文件。 I'm trying to figorue out how to prevent the user from pulling the js files directly (forcing them to pull only a bundle), in order to prevent viewing comments. 我试图弄清楚如何防止用户直接拉出js文件(强制它们仅拉出捆绑包),以防止查看注释。 Is there a way to implement a black list of files that can't be downloaded? 有没有办法实现无法下载的文件黑名单? If not, I was thinking of adding a series of random characters to the name of each js file. 如果没有,我正在考虑在每个js文件的名称中添加一系列随机字符。 Lastly, if that doesn't seem like a good idea, I would investigate injecting something into the VS build process to strip comments on publish. 最后,如果这不是一个好主意,我将调查在VS构建过程中注入一些内容以剥离发布时的注释。

Any thoughts would be welcome. 任何想法都将受到欢迎。

I think you can modify your deployment process. 我认为您可以修改您的部署过程。 To your production server upload only the minified js files but to your test/dev server upload everything. 向生产服务器仅上传缩小的js文件,但向您的测试/开发服务器上传所有内容。

You can use blockviewhandler in a web.config in the folder your js is in. Explicitly whitelist any files that are OK to download and then block the rest. 您可以在js所在文件夹的web.config中使用blockviewhandler。将所有可以下载的文件明确列入白名单,然后阻止其余文件。

There's an example in this question: Where to put view-specific javascript files in an ASP.NET MVC application? 这个问题有一个示例: 将特定于视图的javascript文件放在ASP.NET MVC应用程序中的什么位置?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM