LightSwitch 2013 User Management – HTML – Part 1

Building The Base

This project builds upon a previous project. If you have not already done so, follow the instructions in the following blog post first:

How To Create An Expanded LightSwitch 2013 Project

You will also need the code from GitHub at:
Updated on GitHub: AccountController.cs

LightSwitchUserUserManagement

Make sure you right click on your downloaded file and unblock the file.

All done? Great… lets start!

  1. Under your App_Start folder in your server project, Open WebApiConfig.cs
    Add the following new route

    config.Routes.MapHttpRoute(
    name: "DefaultRpc",
    routeTemplate: "rpc/{controller}/{action}/{id}",
    defaults: new { id = RouteParameter.Optional }
    );
  2. Save and close the WebApiConfig.cs
  3. Add a new folder in the root of your server project name it: DTOs
  4. Add another new folder, this time in your Controllers folder: RpcOdd… but with LightSwitch I have found the easiest way to add external files is to load up an instance of Windows Explore and copy from there. Then back in Visual Studio, show all the files for your project, press the refresh button, then right click on the new files and include in your project.So… lets add some files.
  5. Add the AccountDTOs.cs file from the DTOs folder, in the zip you downloaded from GitHub, to your server project DTOs folder.  Include the file in the project.
  6. Add the AccountController.cs from the RPC folder, in the zip you downloaded from GitHub, to your server project Controller/Rpc folder. Include the file in the project.
  7. Right click on the your server project, select Add, Reference, find and select:  System.Web.ApplicationServices
  8. Open the properties of your LightSwitch main project. Click on the access control tab and add a few permissions so you can see how this works.
  9. Save all
  10. Select Build, Clean solution
  11. Select Build, Build solution
  12. Run your solution…

Hopefully you will get a clean build.

So… now lets talk about good ways to test API/RPC type of calls. You might want to Install Fiddler… it’s a pretty robust product…

But, if you have Google Chrome, Go to the app section in Chrome and install the REST Console. This app does a nice job of including authentication into the calls it makes. Definitely should have this in your tool belt since putting authentication into Fiddler is not so easy.

Now that you have the REST Console installed… you can call some of the functions in the account controller. Notice the /rpc/ in the URL:

http://localhost:{port}/rpc/Account/GetUsers

http://localhost:{port}/rpc/Account/GetApplicationPermissions

etc

Hmmm… didn’t work? Most likely due to the [Authorize] attribute is still turned on in the controller.

For this exercise, go back into the AccountController.cs and comment out the attribute beginning at line 46 of the controller. Then test again.

Pretty cool eh?  Next up will be a full HTML based User Management app.

2 thoughts on “LightSwitch 2013 User Management – HTML – Part 1

  1. […] Then… LightSwitch 2013 User Management – HTML – Part 1 […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 143 other followers

%d bloggers like this: