Hi! I'm Martin Söderlund, the owner of this blog. I work as a web consultant in Stockholm, Sweden. My main focus areas are .NET development and interface development.
If you've got something on your mind, feel free to contact me.


Thank you for visiting!

Please consider subscribing to the RSS feed or following me on Twitter.

Take Ownership on Windows 10

After installing Windows 10, you suddenly don't have permissions to save in some locations. It doesn't matter if you're an administrator either.

After some research, I found a simple solution in this thread on TenForums.

Simply fire up a command prompt (hit Windows key, type CMD, right click and choose Run as administrator) and run this command on your location or drive (change E: to appropriate):

icacls "E:" /setowner "Administrators" /T /C

Depending of the number of files in your location, it might take some time.

Faster Visual Studio Attach to Process Debugging

Visual Studio's Attach to process is an alternative to the good ol' F5 which builds your solution and lets you debug it. However Attach to process can be made a little bit easier using a few helpful tricks.

First of all, we need to add an external tool to Visual Studio:

  1. Go to Tools->External Tools and press Add to create a new tool.
  2. Fill in these values in the correct field:

    Title: list w3wp
    Command: %windir%\system32\inetsrv\appcmd.exe
    Arguments: list wp

    Make sure "Use Output window" is checked and remember what order your tool has in the list, for instance 4th. Press Ok.

Add external tool in Visual Studio

Remember that your w3wp processes will be in Visual Studio's output window when using this tool!

Now we want easy access to our tool. Let's give it a shortcut command:

  1. Go to Tools->Options->Environment->Keyboard.
  2. In the Show command containing box, search for tools.external
  3. Find the correct  Tools.ExternalCommandX where X matches the order of your tool in the external tools list, for instance 4.
    Assign shortcut keys to your command and press Ok. I use Alt+E.

Assign shortcuts in Visual Studio

Next up, we need to use the helpful Visual Studio extension ReAttach. Download and install it. It helps us reattach to the same w3wp process over and over again :-) I've written about ReAttach and debugging before.

Finally, let's assign some shortcut commands to Attach to process and reattach:

Using the same technique as last time:

  1. Search for Debug.AttachtoProcess and assign Alt+W
  2. Search for Debug.ReAttach and assign Alt+Q

Now you can first find your correct process under Alt+E, then attach to it using Alt+W and finally reattach using Alt+Q.

Maybe you want different shortcuts, feel free to do it your way.

Basic ASP.NET MVC Form Validation

Later versions of ASP.NET MVC utilizes jQuery Validate for form validation, and does it well. A few things must be in place for this to work.

I'm going to show you a simple form with a text field and an email address, both of which are required. The email address will also be validated as an email address.

First of all, make sure you use the needed jQuery files. It's important that we use jQuery validate unobtrusive.

The easiest thing here is to install the Nuget package Microsoft.jQuery.Unobtrusive.Validation using Package Manager Console in Visual Studio:

Install-Package Microsoft.jQuery.Unobtrusive.Validation

(Otherwise, you can find the CDN:s on www.asp.net/ajax/cdn)

Don't forget to add the script elements for jQuery and jQuery unobtrusive. It's up to you if you go with the minified versions or the standard versions.

Next up, we will add two properties to our model, preferably a ViewModel.


[Required(ErrorMessage = "*")]
[EmailAddress(ErrorMessage = "*")]
public string Email { get; set; }

[Required(ErrorMessage = "*")]
public string Name { get; set; }

First of all, we declare our properties. We decorate them with the Required and EmailAddress attributes. We need to import the System.ComponentModel.DataAnnotations namespace for this.

As you can see, you can define an error message for both the Required attribute as well as the EmailAddress attribute. I've chosen to just use an asterisk for both now.

Next up, we will render our form:

@using (Html.BeginForm("MyForm", null, FormMethod.Post))
	@Html.LabelFor(x => x.Email, "Email")
	@Html.TextBoxFor(x=>x.EmailTo, new { @placeholder="Email"})
	@Html.ValidationMessageFor(x => x.EmailTo)
	@Html.LabelFor(x => x.Name, "Name")
	@Html.TextBoxFor(x => x.Name, new { @placeholder = "Name" })
	@Html.ValidationMessageFor(x => x.Name)
        <input type="submit" value="Send" />

What is important here is that we use the TextBoxFor and ValidationMessageFor HTML helpers. ValidationMessageFor is what helps us display the error messages we configured in the view model.

Finally, you might want to style the HTML rendered when there's a field with a validation error. There are a few options, styling the input-validation-error css class takes you far.

And this is it! It's all you need to get started with form validation in ASP.NET MVC.

Here are a few useful links if you want to dive deeper into this:

Could Not Find Part of Path for Packages.config in EPiServer

So you got the Could not find a part of the path error when your EPiServer website is looking for Shell\ClientResources\packages.config?

This should be easily resolved:

  1. In episerverFramework.config, make sure that your app data base path is correct:

    <appData basePath="\\SERVER\EPiServer\VPP\ProjectName" />

  2. In your website root, check the modules folder. In the _protected\Shell\ folder, make sure you've got the EPiServer.Shell.UI.zip file. If you don't have it, install a new EPiServer website and copy the zip file from that one. Remember to not mix EPiServer versions too much here.
Hopefully any of these solutions makes it work!


To the top