Running .NET apps from a network share

by Sander Gerz March 24, 2006 11:19

Yesterday, at the dotNed meeting, the question came up why running an .NET application from a network location, such as a share, doesn't work and generates a Security Exception. It seems this question is raised every once in a while, so here's a quick solution using caspol.exe. The reason for it being quick is mainly because caspol can be run from the command-line. Alternatively, you can use the Microsoft .NET Framework 2.0 Configuration Tool, or the Trust Assemblies Location property in Visual Studio (which is useful only during development.).

To grant full trust to a network folder

  • Type the following command in the Visual Studio Command Prompt:

    caspol -m -ag LocalIntranet_Zone -url \\<ServerName>\<FolderName>\* FullTrust -n "<Name>" -d "<Description>"

[source]

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Bitwise operators makes us storagewise

by Sander Gerz March 17, 2006 10:36

Not having a computer science or mathematical background, I had a vague idea of bitwise operators, but never needed them for anything practical. Until now that is. I'm building a form with a CheckedListBox. This listbox contains items that can be checked or unchecked. The items themselves are added from an enumeration, say TestOptions. The user can check multiple items but I only have one variable to store the selection. Ok, I could have more, but figured it to be a waste to check the state of each item and store that in a seperate variable. There should be something more efficient to do this. So here goes:

First here's the enum type:

        public enum TestOptions {

            OptionA = 1,

            OptionB = 2,

            OptionC = 4,

            OptionD = 8

        }

It's important to give each enumvalue an explicit integer value. These values need to be incremented by a multiple of 2 (so: 1, 2, 4, 8, 16, 32, etc). This enables us to make unique combinations of a set of enum values. I.e. the setvalue of 5 can only be attributed to a selection of 1 and 4. The value of 7 can only come from a selection of 1, 2 and 4.

To fill the listbox with items and set their checked state, this method is called:

        private void SetCheckedListBoxItems(int value) {

            foreach (int enumValue in Enum.GetValues(typeof(TestOptions)) ) {

                CheckState state = CheckState.Unchecked;

                if((value & enumValue) == enumValue) {

                    value ^= enumValue;

                    state = CheckState.Checked;                     

                }               

                checkedListBox1.Items.Add(Enum.GetName(typeof(TestOptions), enumValue), state);               

            }

        }

The value that is passed to this method is the sum of the items from the enum that are checked. For example: SetCheckedListBoxItems(9). The method will loop through each enum value. The default state is unchecked. Then we check to see if the submitted value is contained in a bitfield. For integral types like we have here, & computes the bitwise AND of its operands. What this means is that it returns the bits that are common between the two operands. Wait a minute, we went from integer to bit, what, how, when? Well, an integer is composed of 32 bits in the .NET Framework, which means that 32 zeros and ones represent the actual integer value. To clarify, take the value of 9 which can be represented as: 1001. For brevity, let's omit the 28 zeros preceding 1001.

Suppose this value of 9 is submitted to the method shown above. Once in the loop it checks against the value of 2, being one of the enum values. The number 2 in bits is: 0010. The outcome of (1001 & 0010) = 0000, effectively zero, so there's no match and we don't check the item. Further in the loop we get the enumvalue of 8, representable as: 1000. We check which bits are the same (1001 & 1000) and the result is ... 1000, which is 8 in integer terms.

So we know that the item representing the enumvalue of 8 needs to be checked. We then combine the bits such that if exactly one is 1, the result is 1, else the result is 0. For this, we use the ^= operator also known as the exclusive-OR assignment operator. Performing the operation 1001 ^= 1000 sets the value to 0001, which is 1 as an integer. So when the loop encounters the enumvalue of 1, the evaluation will give the proper result, and make sure we also check the listitem for the enumvalue representing 1. You would assume we encounter the value of 1 before we see 8 in our loop through the enumtype and while this is true, it doesn't matter. Try this for yourself.

After a new selection is made, we want to save the new value. This is very simple.

        private void SaveSelection() {

            int newvalue = 0;

            foreach (string item in checkedListBox1.CheckedItems) {

                newvalue += (int)Enum.Parse(typeof(TestOptions), item);

            }

            // show the value, or persist somewhere, whatever...

            MessageBox.Show("value: " + newvalue);

        }

The concept allows for very efficient storage of selections. Looking back on previous apps, I could have used this more in my applications. How about you?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET

Samples on Atlas and other DevDays stuff

by Sander Gerz March 12, 2006 21:51

For those who went to the Dutch DevDays and attended Scott Guthrie's session on Atlas, here's his post on the samples he used.

For those who attended my session on authentication in ASP.NET 2.0 and how to upgrade from ASP and ASP.NET 1.1, here are the samples I used.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Testing exams 70-553 and 70-554

by Sander Gerz March 06, 2006 13:57

This morning I took the beta exams for 70-553 and 70-554 (71-* when they're in beta). Both exams are pretty big, but I took it as the challenge to take both at the same time. Well, not exactly of course, first 553 and then 554, but on the same day. I had not anticipated the total number of questions though, about 150!

553 dealt more with C# (in my case, you can also pick VB.NET) language constructs, a bit of Windows Forms. I should have taken more interest in the BackgroundWorker component, but in all the questions were not extremely difficult. That's no guarantee for success on my part. After about 70 questions, I experienced a lapse of concentration.

The 554 is more focused on 'enterprise' development. That's probably why about every question in the first part of the exam starts with 'you are an enterprise developer...'. The second part was very much on Web Services Enhancements 3.0 and bit of .NET remoting. These were some tough questions. Partly due to my lack of experience with WSE 3.0.

The lack of experience is mostly what makes the exams difficult. Since both exams are targeted at .NET certified developers, the focus is primarily on new features. And given the limited time .NET 2.0 has really been on the market, only few of us really have indepth experience with WSE 3.0, ClickOnce deployment, Providers, mobile devices, new asynchronous capabilities. At the same time and on the same level, that is.

The exams themselves are divided in three and two parts respectively, so don't be fooled when you enter the exam and see 30 questions and 1 hour remaining when you start. If I remember correctly when upgrading my MCSE on NT4 to Win2000 certification, that was a question marathon as well.

I'll get the result in a couple of weeks, but I'm not keeping my fingers crossed until then. I have some preparing to do for my session at the Dutch DevDays tomorrow.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen | Modified by Mooglegiant