简体   繁体   English

ASP.NET MVC3-限制用户的捆绑包配置代码

[英]ASP.NET MVC3 - Restrict Bundle Config Code from user

I have registered bundles using below code in Global.asax.cs file. 我已经在Global.asax.cs文件中使用以下代码注册了捆绑包。 When I enter domain name with bundles path in browser, I am able to view js content in browser. 在浏览器中输入带有捆绑路径的域名时,可​​以在浏览器中查看js内容。 Below URL should not display any content in the browser. 以下网址不应在浏览器中显示任何内容。

At least I would like to restrict user access to url if it has bundles. 至少我想限制用户访问url(如果有捆绑包)。 Is it possible to restrict bundles only to user and not to browser? 是否可以将捆绑软件仅限制于用户而不限制于浏览器?

https://myworld.com/home/bundles/jqueryval https://myworld.com/home/bundles/jqueryval

https://myworld.com/home/bundles/globalization https://myworld.com/home/bundles/globalization

bundles.Add(new ScriptBundle("~/bundles/jqueryval")
    .Include("~/Scripts/jquery.validate.js")
    .Include("~/Scripts/jquery.validate.unobtrusive.js"));

bundles.Add(new ScriptBundle("~/bundles/globalization")
    .Include("~/Scripts/globalize/globalize.js")
    .Include("~/Scripts/globalize/cultures/globalize.culture.es-CL.js")
    .Include("~/Scripts/jquery.validate.globalize.js"));

Your bundles are JavaScript and CSS files. 您的捆绑包是JavaScript和CSS文件。 It should be public and accessible so that the browser can download and execute them. 它应该是公共的并且可以访问,以便浏览器可以下载并执行它们。 And you cannot disable them from user being viewed. 而且,您无法将其禁止用户查看。 It can be minified but you can't hide them from user. 它可以缩小,但是您不能对用户隐藏它们。

You can enable or disable using below code. 您可以使用以下代码启用或禁用。 If you disable then browser also cannot access it. 如果禁用,则浏览器也将无法访问它。

BundleTable.EnableOptimizations = true; 
BundleTable.EnableOptimizations = false;

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

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