Is there a way to prevent some variables from being renamed via asp.net System.Web.Optimization


Darren Wainwright

I'm using ASP.Net bundling and minification ( ) System.Web.Optimizationin an AngularJS project .

Everything works fine except for one case.

At this point, we must eval()express. We know this isn't ideal, although no other solution currently meets our needs.

So we have this line:

var isValid = eval('globalJson.Permissions.' + attrs.drHasPermissionFor);

Now this line fails because minification changes the names of our variables etc.globalJson

Is there a way to instruct ASP.Net Minification not to rename specific variables?

Updates

Starting from the answer given - we've used the Angulars safe way to inject.

The directive to use this directive looks like this:

    appDirectives.directive('drHasPermissionFor', ['globalJson', function (globalJson) {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                //code .....

                // how can I reference the injected globalJson here - so that i know it's using the
                // newly minified name..
                var isValid = eval('globalJson.Permissions.' + attrs.drHasPermissionFor);

//more code......
            }
        };
    }]);
Darren Wainwright

OK - a colleague figured out a solution to this particular problem.

While it solves the problem at hand, it doesn't really answer the overall "can you tell optimization to keep some variables independent".

If the first question should be answered, I'll happily change the accepted answer.

As it stands, it can be hacked like this:

appDirectives.directive('drHasPermissionFor', ['globalJson', function (globalJson) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {

            // this function will return the minified globalJson
            function returnGlobalJson() {
                return globalJson;
            };

            // call this function as part of the eval - works perfectly :)
            var isValid = eval('returnGlobalJson().Permissions.' + attrs.drHasPermissionFor);

        }
    };
}]);

Related


Prevent specific asp.net page from being logged out

my husband I have a specific page in a webform application where I never want to log out. It's not in the master page. There is an auto-refresh tag in the header that refreshes the entire page at intervals: (added via code) Everything works fine, but it seems

prevent some standard functions from being called

ninja hat For some reason we shouldn't use some std functions in our std::sort()codebase (for which we have our own implementation). Is there a way to prevent these functions from being called, preferably throwing an error at compile time? I looked at the over

prevent some standard functions from being called

ninja hat For some reason we shouldn't use some std functions in our std::sort()codebase (for which we have our own implementation). Is there a way to prevent these functions from being called, preferably throwing an error at compile time? I looked at the over

Prevent backspace from navigating backwards in asp.net web form

ProgramsGuy I have an asp.net web form with some read only fields. My problem is that if the user selects the read-only textbox and presses backspace to try to delete the content in that textbox, it returns to the page in the form. I'm using IE 11 and can't se

Prevent backspace from navigating backwards in asp.net web form

ProgramsGuy I have an asp.net web form with some read only fields. My problem is that if the user selects the read-only textbox and presses backspace to try to delete the content in that textbox, it returns to the page in the form. I'm using IE 11 and can't se

Prevent backspace from navigating backwards in asp.net web form

ProgramsGuy I have an asp.net web form with some read only fields. My problem is that if the user selects the read-only textbox and presses backspace to try to delete the content in that textbox, it returns to the page in the form. I'm using IE 11 and can't se

Prevent href in <a></a> from being executed via Javascript

Syrah So I have the following code in my HTML: <li class="" id="toolbar_section"><a id="toolbar_section_child" href="#foobar" onclick="return toolbarSetSection(this);" data-toggle="checkpoint">foobar</a></li> Written in my Javascript is: <script type="text/ja

bash: prevent variables from being evaluated

Sal I have a variable that stores the directory path (optional, owner, group) and permissions, separated by a pipe: line='/opt/temp/dir/*|||a+r' If I echo $line, I get the directory substring the way I expect and need: ~ /opt/temp/dir/*|||a+r So now I need t

Prevent variables from being overwritten in submakefiles

ancient I have a makefile that compiles a shared library and I am calling it from another makefile. When developing libraries, I use variables TARGETto name library binaries. BUILD_DIR?=$(abspath ./build) SRC=src/file.c INC=-I inc CFLAGS+=-Wall -Werror LDFLAG

How to prevent variables from being reset

Sheku Kanneh In my code I have a method with two parameters. One parameter takes an int value and the other takes an array. E.g public void NextSong(int i, TagLib.File[] queue) { i++; SONG_URL = queue[i].Name; Stop(); Play(); } My problem i

How to prevent variables from being reset

Sheku Kanneh In my code I have a method with two parameters. One parameter takes an int value and the other takes an array. E.g public void NextSong(int i, TagLib.File[] queue) { i++; SONG_URL = queue[i].Name; Stop(); Play(); } My problem i

bash: prevent variables from being evaluated

Sal I have a variable that stores the directory path (optional, owner, group) and permissions, separated by a pipe: line='/opt/temp/dir/*|||a+r' If I echo $line, I get the directory substring the way I expect and need: ~ /opt/temp/dir/*|||a+r So now I need t

bash: prevent variables from being evaluated

Sal I have a variable that stores the directory path (optional, owner, group) and permissions, separated by a pipe: line='/opt/temp/dir/*|||a+r' If I echo $line, I get the directory substring the way I expect and need: ~ /opt/temp/dir/*|||a+r So now I need t

Prevent variables from being inlined in SQL Server

NS.X. I have a problem with a stored procedure that incrementally copies data from one table to another: DECLARE @StartId bigint; SELECT @StartId = COALESCE(MAX(Id), 0) FROM dbo.TargetTable WITH (NOLOCK); INSERT INTO dbo.TargetTable (...) SELECT ...

Prevent variables from being inlined in SQL Server

NS.X. I have a problem with a stored procedure that incrementally copies data from one table to another: DECLARE @StartId bigint; SELECT @StartId = COALESCE(MAX(Id), 0) FROM dbo.TargetTable WITH (NOLOCK); INSERT INTO dbo.TargetTable (...) SELECT ...

Prevent string variables from being destroyed

Kaleb The question here is simple, but it really annoys me. I have a small function here: (defn something [start-url n] (loop [urls start-url index n] (if (= index 0) (set urls) (recur (flatten (pmap

bash: prevent variables from being evaluated

Sal I have a variable that stores the directory path (optional, owner, group) and permissions, separated by a pipe: line='/opt/temp/dir/*|||a+r' If I echo $line, I get the directory substring the way I expect and need: ~ /opt/temp/dir/*|||a+r So now I need t