<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>From The Depths</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/mthalman/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/mthalman/feed.xml</link>
    <description>Matt Thalman&amp;#039;s blog: Senior developer working on Microsoft&amp;#039;s Visual Studio LightSwitch product.</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:20:52 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>How to Get a Stack Trace in LightSwitch</title>
      <link>https://docs.microsoft.com/archive/blogs/mthalman/how-to-get-a-stack-trace-in-lightswitch</link>
      <pubDate>Fri, 16 Aug 2013 07:21:34 GMT</pubDate>
      <dc:creator><![CDATA[Matt Thalman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mthalman/2013/08/16/how-to-get-a-stack-trace-in-lightswitch/</guid>
      <description><![CDATA[A lot of times LightSwitch customers will run into an error in the product and post a question on...]]></description>
      <content:encoded><![CDATA[<p>A lot of times LightSwitch customers will run into an error in the product and post a question on the <a href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=lightswitch">forums</a> but the LightSwitch development team needs more information about the error.&#160; This blog post describes how you can help the LightSwitch development team determine the source of those kinds of errors you may encounter.&#160; Unexpected errors (or exceptions as we call them) within the product can manifest themselves either by an error message, a crash, lack of response (hang), or when an expected behavior doesn’t occur.&#160; By providing an exception stack trace in your <a href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=lightswitch">forum</a> posts, it provides valuable information to the development team and helps us help you.</p>  <h2>Exception Lead-In</h2>  <p>Before beginning the process of debugging, you’ll want to follow the necessary steps in Visual Studio or your LightSwitch app that reproduce the exception but stopping just prior to the last step that actually causes the exception.&#160; If you attach and debug prior to all these steps you may encounter a bunch of exceptions that are unrelated to the issue or performance of the process may be degraded enough that will make you annoyed.&#160; So just get to the point right before the exception occurs and then follow the instructions below.</p>  <h2>Attaching to the Process</h2>  <p>The next step is to identify which process to debug.&#160; This handy flowchart can help you determine which process you should be attached to in order to retrieve the exception stack trace:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5076.image_35DA70E1.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/5076.image_5F00_35DA70E1.png"><img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/7658.image_thumb_2E4F0174.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/7658.image_5F00_thumb_5F00_2E4F0174.png" width="378" height="302" /></a></p>  <p>Note that if the issue you’re investigating occurs within your running application while you are running it from within Visual Studio via F5, Visual Studio will automatically be attached to both the client and server processes.&#160; In all other cases, you’ll need to manually attach to the process.&#160; Of course, if the issue occurs within Visual Studio itself, you’ll need to launch another instance of Visual Studio to attach to the original instance since a given VS process cannot attach to itself.</p>  <p>To manually attach to the process, go to “Tools –&gt; Attach to Process…” in Visual Studio.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/8304.image_71CB66D1.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/8304.image_5F00_71CB66D1.png"><img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/2330.image_thumb_3F679352.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/2330.image_5F00_thumb_5F00_3F679352.png" width="318" height="95" /></a></p>  <p>In the dialog that opens, select the name of the process as indicated by the flowchart above.&#160; This will only allow you to attach to the process if it is running on the local machine.&#160; If you want to attach to a remote process (for example, attach to the IIS process on a remote machine), you’ll need to follow the instructions in this MSDN article: <a href="http://msdn.microsoft.com/en-us/library/vstudio/bt727f1t.aspx">Setup Remote Debugging</a>.&#160; If the process is hosted on a machine you don’t have access to, like Azure, you won’t be able to follow the debugging instructions described in this post.&#160; Instead, you’ll need to use diagnostic tracing as described in this post: <a href="http://blogs.msdn.com/b/lightswitch/archive/2012/10/06/10212677.aspx">Diagnosing Problems in a Deployed 3-Tier LightSwitch Application</a>.</p>  <h2>Configure for Debugging</h2>  <p>Now that Visual Studio is attached to the process, it needs to be properly configured to break on exceptions in order to see the stack trace of the exceptions.</p>  <p>The first thing to do is to ensure that VS is configured to debug code that you don’t own.&#160; Visual Studio has a feature called “<a href="http://msdn.microsoft.com/en-us/library/h5e30exc%28v=VS.80%29.aspx">Enable Just My Code</a>” that is enabled by default which prevents you from debugging code that isn’t yours.&#160; To turn it off, follow these steps:</p>  <ol>   <li>Go to Tools –&gt; Options.</li>    <li>If necessary, click the “Show all settings” check box at the bottom of the dialog if the “Debugging” node doesn’t show up in the tree.</li>    <li>In the Options dialog, navigate to Debugging –&gt; General in the tree.</li>    <li>Ensure that the “Enable Just My Code” check box is not checked.</li> </ol>  <p align="center"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/6683.image_4A24EAA7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/6683.image_5F00_4A24EAA7.png"><img title="image" style="border: 0px currentcolor; display: inline;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/3365.image_thumb_571ECAB8.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/3365.image_5F00_thumb_5F00_571ECAB8.png" width="403" height="235" /></a> </p>  <p>&#160;</p>  <p>The next thing is to configure VS so that it will break when an exception is thrown.&#160; To do this, open the Exceptions dialog: Debug –&gt; Exceptions.&#160; In the Exceptions dialog, find the category of exceptions you want to break on and check its check box in the “Thrown” column.&#160; For server and Silverlight client debugging, you’ll want to use the Common Language Runtime Exceptions; for HTML clients, you’ll want to use the JavaScript Runtime Exceptions.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/8270.image_36978B06.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/8270.image_5F00_36978B06.png"><img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5852.image_thumb_2F0C1B99.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/5852.image_5F00_thumb_5F00_2F0C1B99.png" width="397" height="195" /></a></p>  <p>This will break on all exceptions of that category.&#160; A lot of times there will be exceptions thrown that are irrelevant to the actual issue.&#160; These are normal and are handled by the LightSwitch code.&#160; If you know the specific exception type that you want to break on, you can configure this dialog to break only on that exception type by drilling into the Common Language Runtime Exceptions node and finding the exception or by clicking the Find button and searching for it that way.</p>  <h2>Reproduce the Exception</h2>  <p>You’re now ready to do the final step in Visual Studio or your LightSwitch app that actually causes the exception to occur.&#160; Once you do that, you’ll see an exception message appear in Visual Studio that looks like this:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/2744.image_3C722E9F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/2744.image_5F00_3C722E9F.png"><img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5305.image_thumb_230A2B65.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/5305.image_5F00_thumb_5F00_230A2B65.png" width="351" height="323" /></a></p>  <p>Or like this if you’re debugging an HTML client:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/1614.image_4657200A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/1614.image_5F00_4657200A.png"><img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/0624.image_thumb_33A22653.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/0624.image_5F00_thumb_5F00_33A22653.png" width="354" height="202" /></a></p>  <p>&#160;</p>  <p>As mentioned earlier, there can be exceptions that are thrown that are properly handled by LightSwitch and irrelevant to your actual issue.&#160; You’ll want to work with someone on the LightSwitch development team via the forums or e-mail to determine which exception is the one that is relevant.&#160; If you know the exception is not relevant, you can continue execution by clicking the “Continue” button.</p>  <h2>Collect Exception Information</h2>  <p>Once you’ve found the exception, click the “Copy exception detail to the clipboard” in the exception window if it’s a .NET exception and paste the result into your favorite text editor.&#160; If it’s a JavaScript exception, there won’t be a link to do this so just skip that step.&#160; Now, you’ll still need to collect a little more information since that exception detail won’t include a detailed stack trace.&#160; Click the “OK” or “Break” button in the exception window to dismiss the window.&#160; Open the Call Stack window in Visual Studio: Debug –&gt; Windows –&gt; Call Stack.&#160; Select all of the lines in it (Ctrl+A) and copy it to the clipboard (Ctrl+C).</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5342.image_7A1F165B.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/5342.image_5F00_7A1F165B.png"><img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5282.image_thumb_64552DFE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/5282.image_5F00_thumb_5F00_64552DFE.png" width="418" height="150" /></a></p>  <p>Paste that text along with the other exception detail you collected into the text editor.&#160; You’ve now collected enough information to pass along to the LightSwitch development team.&#160; Of course, along with the exception information, you should still describe the set of steps that reproduce the issue.</p>  <h4>HTML Clients</h4>  <p>If you’re debugging a JavaScript exception, the stack trace will probably have a lot of single letters for function names.&#160; This happens because you’re app is configured to use the minified versions of the runtime JavaScript files.&#160; To provide a more informative stack trace, change your default.htm file of your HTML client and remove “.min” from all of the filenames of the referenced scripts.</p>  <blockquote>   <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/6378.image_2A65EB12.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/6378.image_5F00_2A65EB12.png"><img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5807.image_thumb_37CBFE18.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/5807.image_5F00_thumb_5F00_37CBFE18.png" width="424" height="76" /></a></p> </blockquote>  <p>Then follow the steps to reproduce the issue again.&#160; This time it will provide the friendly function names in the stack trace which is much more useful.&#160; Be sure to revert your changes to the default.htm file when you’re done debugging.</p>]]></content:encoded>
    </item>
    <item>
      <title>Customizing LightSwitch User Management</title>
      <link>https://docs.microsoft.com/archive/blogs/mthalman/customizing-lightswitch-user-management</link>
      <pubDate>Tue, 25 Jun 2013 11:57:56 GMT</pubDate>
      <dc:creator><![CDATA[Matt Thalman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mthalman/2013/06/25/customizing-lightswitch-user-management/</guid>
      <description><![CDATA[When you enable Windows or Forms authentication in a LightSwitch app, a set of SQL tables are used...]]></description>
      <content:encoded><![CDATA[<p>When you enable Windows or Forms authentication in a LightSwitch app, a set of SQL tables are used to store the user and role data.&#160; But did you know that you can customize how and where LightSwitch gets the user and role data?&#160; You don’t <em>have</em> to use the default set of SQL tables that LightSwitch generates in its intrinsic database.&#160; This post describes in detail how you can go about customizing the management of users and roles in your LightSwitch app.</p>  <p><font size="4"></font></p>  <h1><font size="4">Extensible Design</font></h1>  <p>LightSwitch makes use of many APIs within ASP.NET.&#160; Among those are the provider classes for user and role management.&#160; You can learn more about these providers and their associated APIs on MSDN:</p>  <ul>   <li><a href="http://msdn.microsoft.com/en-us/library/tw292whz(v=vs.100).aspx">Managing Users by Using Membership</a></li>    <li><a href="http://msdn.microsoft.com/en-us/library/9ab2fxh0(v=vs.100).aspx">Managing Authorization Using Roles</a></li> </ul>  <p>The great thing about this provider model is that it is configurable outside of source code.&#160; You can configure your app, defining which providers to use and their settings, by editing your web.config file.&#160; And since all providers have a common set of base classes, LightSwitch doesn’t need to know which provider type it’s using; the web.config file and ASP.NET dictate which providers LightSwitch uses.</p>  <p>There are a set of base provider classes that we’re interested in here:</p>  <ul>   <li><a href="http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.aspx">System.Web.Security.MembershipProvider</a>: This class defines the interface used to access user information such as the login name and password of a user.</li>    <li><a href="http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.aspx">System.Web.Security.RoleProvider</a>: This class defines the interface used to access role information (e.g. SalesPerson or Manager).</li>    <li><a href="http://msdn.microsoft.com/en-us/library/system.web.profile.profileprovider.aspx">System.Web.Profile.ProfileProvider</a>: This class defines the interface used to access custom user-specific data.&#160; This is data that the application itself wants to track along with the user.&#160; ASP.NET doesn’t track any data of its own here; this is all application-specific.</li> </ul>  <p>LightSwitch makes use of each of these provider types and each of them can have a custom implementation that LightSwitch will invoke.</p>  <p><font size="4"></font></p>  <h1><font size="4">How LightSwitch Works</font></h1>  <p>Before I get into how you can customize the user and role management, I wanted to describe how LightSwitch configures things.&#160; Understanding this will allow you to be better informed when time comes to do the customizing.</p>  <p>LightSwitch makes use of the following implementations of the previously mentioned base provider classes:</p>  <ul>   <li><a href="http://msdn.microsoft.com/en-us/library/system.web.security.sqlmembershipprovider.aspx">System.Web.Security.SqlMembershipProvider</a></li>    <li><a href="http://msdn.microsoft.com/en-us/library/system.web.security.sqlroleprovider.aspx">System.Web.Security.SqlRoleProvider</a></li>    <li><a href="http://msdn.microsoft.com/en-us/library/system.web.profile.sqlprofileprovider.aspx">System.Web.Profile.SqlProfileProvider</a></li> </ul>  <p>Each of these classes are implementations of the base provider interface such that they make use of a set of SQL tables to store and retrieve their respective data.&#160; For example, the SqlMembershipProvider implementation makes use of a combination of the aspnet_Membership and aspnet_Users tables contained in the LightSwitch intrinsic database.</p>  <p>If you enable authentication in your LightSwitch app, save, and open your web.config file, you’ll see how LightSwitch configures the use of these providers.&#160; For more information on configuring authentication in your LightSwitch app, see <a href="http://msdn.microsoft.com/library/vstudio/ff851957.aspx">LightSwitch Authentication and Authorization</a>.</p>  <h5>Membership Provider</h5>  <p>LightSwitch uses the membership provider to store the users that have access to the application.&#160; When you log into a LightSwitch app with your username and password, for example, LightSwitch makes use of the membership provider to ensure 1) you exist as an application user and 2) your password matches.</p>  <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">   <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">     <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">membership</span> <span style="color: rgb(255, 0, 0);">defaultProvider</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetMembershipProvider&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>   <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">clear</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">add</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>       <span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetMembershipProvider&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>       <span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">=&quot;System.Web.Security.SqlMembershipProvider&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>       <span style="color: rgb(255, 0, 0);">connectionStringName</span><span style="color: rgb(0, 0, 255);">=&quot;_IntrinsicData&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span>       <span style="color: rgb(255, 0, 0);">applicationName</span><span style="color: rgb(0, 0, 255);">=&quot;Application10&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span>       <span style="color: rgb(255, 0, 0);">requiresUniqueEmail</span><span style="color: rgb(0, 0, 255);">=&quot;false&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum10" style="color: rgb(96, 96, 96);">  10:</span>       <span style="color: rgb(255, 0, 0);">requiresQuestionAndAnswer</span><span style="color: rgb(0, 0, 255);">=&quot;false&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum11" style="color: rgb(96, 96, 96);">  11:</span>   <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum12" style="color: rgb(96, 96, 96);">  12:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">membership</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF--></div>
</div>
The snippet above shows how LightSwitch configures the membership provider when Forms authentication is being used.&#160; I’ll explain each of the lines in that snippet so it all makes sense: 

<blockquote>
  <p>Line #1: The <a href="http://msdn.microsoft.com/en-us/library/vstudio/1b9hw62f(v=vs.100).aspx">membership element</a> configures the ASP.NET membership management.&#160; It contains a defaultProvider attribute which references the name of membership provider defined below that should be used by default.</p>

  <p>Line #2: The <a href="http://msdn.microsoft.com/en-us/library/vstudio/6d4936ht(v=vs.100).aspx">providers element</a> defines the collection of membership providers and their configurations.&#160; Obviously, this implies you can define multiple membership providers in this section which ASP.NET supports.&#160; LightSwitch does not support multiple providers.&#160; Only the membership provider marked as the default (via the defaultProvider attribute on the membership element) will be used.</p>

  <p>Line #3: The <a href="http://msdn.microsoft.com/en-us/library/vstudio/t062y6yc(v=vs.100).aspx">clear element</a> simply ensures that the providers element collection is cleared prior to adding the membership provider.&#160; This isn’t strictly necessary but it ensures that there are no extraneous providers included in the collection that may have been added by fancy things like <a href="http://msdn.microsoft.com/en-us/library/ms178685(v=vs.100).aspx">web.config inheritance</a>.</p>

  <p>Line #4: The <a href="http://msdn.microsoft.com/en-us/library/vstudio/whae3t94(v=vs.100).aspx">add element</a> defines which membership provider should be added to the collection and how it should be configured.&#160; It has several attributes that are configured by LightSwitch by default.</p>

  <p>Line #5: The name attribute is an identifier for the provider within the web.config so that it can be referenced as the default provider.</p>

  <p>Line #6: The type attribute is the .NET type name of the membership provider.</p>

  <p>Line #7: The connectionStringName attribute is the name of the connection string that this membership provider should used when accessing the database tables.</p>

  <p>Line #8: The applicationName attribute is the name of the application with which to associate the membership data.&#160; ASP.NET’s implementation of the SqlMembershipProvider allows you to have multiple applications all share the same database but partition, or share depending on how things are configured, the user information between those applications.&#160; Applications that have membership providers configured with the same application name will share the membership data; if they are different application names, the membership data will be separate between the apps.</p>

  <p>Line #9: The requiresUniqueEmail attribute indicates whether a unique e-mail address is required for the user.&#160; By default, SqlMembershipProvider sets this value to true.&#160; LightSwitch doesn’t collect an e-mail address for a user, so this is set to false.</p>

  <p>Line #10: The requiresQuestionAndAnswer attribute indicates whether a password question/answer pair is required for the user to allow for password reset and retrieval.&#160; By default, SqlMembershipProvider sets this to true.&#160; Again, since LightSwitch doesn’t use e-mail addresses, this is set to false.</p>
</blockquote>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">membership</span> <span style="color: rgb(255, 0, 0);">defaultProvider</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetMembershipProvider&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>   <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">clear</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">add</span> <span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetMembershipProvider&quot;</span> <span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">=&quot;Microsoft.LightSwitch.Security.ServerGenerated.Implementation.WindowsUserMembershipProvider, Microsoft.LightSwitch.Base.Server, Version=11.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot;</span> <span style="color: rgb(255, 0, 0);">connectionStringName</span><span style="color: rgb(0, 0, 255);">=&quot;_IntrinsicData&quot;</span> <span style="color: rgb(255, 0, 0);">applicationName</span><span style="color: rgb(0, 0, 255);">=&quot;Application10&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>   <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">membership</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF--></div>
</div>

<p></p>

<p>The snippet above shows how LightSwitch configures the membership provider when Windows authentication is being used.&#160; For Windows authentication, LightSwitch continues to use SQL-based storage to track which Windows users have access.&#160; Even in the case where the app has been configured to allow access to any authenticated Windows user, LightSwitch will still make use of this storage to track which app-defined roles are assigned to any of those users.&#160; LightSwitch makes use of a custom implementation membership provider, derived from SqlMembershipProvider that adds some extra logic specific to handling Windows users and also correctly defaults most of the settings which is why you don’t see the requiresUniqueEmail and requiresQuestionAndAnswer settings here.&#160; Note that the type attribute is set using an <a href="http://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname.aspx">assembly-qualified</a> type name since this is a custom type that is not defined by ASP.NET.</p>

<h5>Role Provider</h5>

<p>LightSwitch uses the role provider to store the roles that have been defined within the app and to map those roles to users.</p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">roleManager</span> <span style="color: rgb(255, 0, 0);">enabled</span><span style="color: rgb(0, 0, 255);">=&quot;True&quot;</span> <span style="color: rgb(255, 0, 0);">defaultProvider</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetRoleProvider&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>   <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">clear</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">add</span> <span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetRoleProvider&quot;</span> <span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">=&quot;System.Web.Security.SqlRoleProvider&quot;</span> <span style="color: rgb(255, 0, 0);">connectionStringName</span><span style="color: rgb(0, 0, 255);">=&quot;_IntrinsicData&quot;</span> <span style="color: rgb(255, 0, 0);">applicationName</span><span style="color: rgb(0, 0, 255);">=&quot;Application10&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>   <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">roleManager</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF--></div>
</div>

<p>The snippet above shows how LightSwitch configures the role provider when any authentication is being used.&#160; It’s pretty much the same structure as the membership snippet.&#160; The only real difference is that the <a href="http://msdn.microsoft.com/en-us/library/vstudio/ms164660(v=vs.100).aspx">roleManager</a> element has an enabled attribute.&#160; That attribute needs to be set to true in order to enable the use of roles in the ASP.NET API.&#160; Just like with the membership provider, LightSwitch only makes use of the role provider that is defined as the default provider.</p>

<h5>Profile Provider</h5>

<p>LightSwitch uses the profile provider to store some extra information about the user in the case where Forms authentication is being used.&#160; In general, the profile provider can be used to track other custom data for a user that is not represented in the membership provider/SQL schema.&#160; In the case of LightSwitch, it keeps track of the full name (display name) of a user, so the profile provider is configured to store this data.</p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">profile</span> <span style="color: rgb(255, 0, 0);">enabled</span><span style="color: rgb(0, 0, 255);">=&quot;True&quot;</span> <span style="color: rgb(255, 0, 0);">defaultProvider</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetProfileProvider&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>   <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">clear</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">add</span> <span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetProfileProvider&quot;</span> <span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">=&quot;System.Web.Profile.SqlProfileProvider&quot;</span> <span style="color: rgb(255, 0, 0);">connectionStringName</span><span style="color: rgb(0, 0, 255);">=&quot;_IntrinsicData&quot;</span> <span style="color: rgb(255, 0, 0);">applicationName</span><span style="color: rgb(0, 0, 255);">=&quot;Application10&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>   <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>   <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">properties</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">add</span> <span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">=&quot;FullName&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span>   <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">properties</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">profile</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF--></div>
</div>

<p>The snippet above shows how LightSwitch configures the profile provider.&#160; It follows the same structure as the other two snippets except for the properties child element.&#160; The <a href="http://msdn.microsoft.com/en-us/library/vstudio/ms164644(v=vs.100).aspx">profile</a> element contains a properties child element that allows a developer to define the names of properties that should be associated with each user.&#160; In the case of LightSwitch, it defines a FullName property here.&#160; Just as with the other providers, LightSwitch only makes use of the profile provider that is defined as the default provider.</p>

<h5>Permission Mapping</h5>

<p>ASP.NET has the concepts of users (membership), roles, and profiles of which LightSwitch makes use.&#160; But ASP.NET does not have the concept of permissions, while LightSwitch does.&#160; So LightSwitch defines its own table, named RolePermissions, within the intrinsic database to map roles and permissions as that is how permissions are assigned in LightSwitch apps.&#160; There does not exist an ASP.NET provider that accesses this table; LightSwitch uses technology outside of ASP.NET to access this table.&#160; For this reason, the storage of role-permission mappings is not customizable.&#160; You can customize how and where roles are stored but when LightSwitch needs to map a permission to that role, it always stores that mapping information in the RolePermissions table.
  <br /></p>

<h3>ASP.NET Provider Customization</h3>

<p>Now that you understand how LightSwitch configures the ASP.NET providers it uses, let’s get into how you can go about customizing them.&#160; There are a few ways you can go about customizing the providers:</p>

<ul>
  <li><strong>Configure</strong> provider properties via the web.config</li>

  <li><strong>Replace</strong> with an existing provider class implementation</li>

  <li><strong>Define</strong> a custom provider</li>
</ul>

<h5>Configuring Provider Properties</h5>

<p>The easiest but least flexible way to customize an ASP.NET provider is to configure its properties within the web.config file.&#160; For example, if you want to change the maximum number of password attempts allowed for a user from the default of 5 to 10, you would set the maxInvalidPasswordAttempts attribute in the add element of the default membership provider configured by LightSwitch (see line #9):</p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">membership</span> <span style="color: rgb(255, 0, 0);">defaultProvider</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetMembershipProvider&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>   <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">clear</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">add</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>       <span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetMembershipProvider&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>       <span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">=&quot;System.Web.Security.SqlMembershipProvider&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>       <span style="color: rgb(255, 0, 0);">connectionStringName</span><span style="color: rgb(0, 0, 255);">=&quot;_IntrinsicData&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span>       <span style="color: rgb(255, 0, 0);">applicationName</span><span style="color: rgb(0, 0, 255);">=&quot;Application10&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span>       <span style="color: rgb(255, 0, 0);">maxInvalidPasswordAttempts</span><span style="color: rgb(0, 0, 255);">=&quot;10&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum10" style="color: rgb(96, 96, 96);">  10:</span>       <span style="color: rgb(255, 0, 0);">requiresUniqueEmail</span><span style="color: rgb(0, 0, 255);">=&quot;false&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum11" style="color: rgb(96, 96, 96);">  11:</span>       <span style="color: rgb(255, 0, 0);">requiresQuestionAndAnswer</span><span style="color: rgb(0, 0, 255);">=&quot;false&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum12" style="color: rgb(96, 96, 96);">  12:</span>   <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum13" style="color: rgb(96, 96, 96);">  13:</span>  <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">membership</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF--></div>
</div>

<p>If you had a separate database location where your ASP.NET users and roles were stored, you could configure your providers to use that database by simply adding a connection string to your web.config file and setting the connectionStringName attributes of your providers to reference that connection string.</p>

<p>Consult the documentation of the provider type in order to determine which properties it defines that are configurable through the web.config file.</p>

<h5>Replacing a Provider</h5>

<p>If there already exists an implementation of an ASP.NET provider different than the default one used by LightSwitch that you want to use, you can simply configure the web.config file to reference that provider type and LightSwitch will make use of it.&#160; To do this, follow these steps: </p>

<ol>
  <li>Add a reference to the assembly that contains the provider type you want to use from your LightSwitch app’s Server project, being sure to set the “Copy Local” property to true for the assembly reference.&#160; This will ensure that the assembly will be copied to the runtime environment.</li>

  <li>Set the add element’s type attribute for that provider to be the assembly-qualified type name of the provider type you want to use.&#160; For example, see line #6:</li>
</ol>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">membership</span> <span style="color: rgb(255, 0, 0);">defaultProvider</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetMembershipProvider&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>   <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">clear</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">add</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>       <span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">=&quot;AspNetMembershipProvider&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>       <span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">=&quot;SomeLibrary.SomeMembershipProvider,SomeLibrary&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>       <span style="color: rgb(255, 0, 0);">connectionStringName</span><span style="color: rgb(0, 0, 255);">=&quot;_IntrinsicData&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span>       <span style="color: rgb(255, 0, 0);">applicationName</span><span style="color: rgb(0, 0, 255);">=&quot;Application10&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span>       <span style="color: rgb(255, 0, 0);">requiresUniqueEmail</span><span style="color: rgb(0, 0, 255);">=&quot;false&quot;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum10" style="color: rgb(96, 96, 96);">  10:</span>       <span style="color: rgb(255, 0, 0);">requiresQuestionAndAnswer</span><span style="color: rgb(0, 0, 255);">=&quot;false&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum11" style="color: rgb(96, 96, 96);">  11:</span>   <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">providers</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum12" style="color: rgb(96, 96, 96);">  12:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">membership</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF--></div>
</div>

<h5>Defining a Custom Provider</h5>

<p>In order to write your own custom provider, you define a class that inherits from the appropriate provider base type (<a href="http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.aspx">System.Web.Security.MembershipProvider</a>, <a href="http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.aspx">System.Web.Security.RoleProvider</a>, or <a href="http://msdn.microsoft.com/en-us/library/system.web.profile.profileprovider.aspx">System.Web.Profile.ProfileProvider</a>) and update the web.config just as was explained in the previous “Replacing a Provider” section.</p>

<p>MSDN provides good documentation on how to go about implementing a custom provider:</p>

<ul>
  <li><a href="http://msdn.microsoft.com/en-us/library/f1kyba5e(v=vs.100).aspx">Implementing a Membership Provider</a></li>

  <li><a href="http://msdn.microsoft.com/en-us/library/8fw7xh74(v=vs.100).aspx">Implementing a Role Provider</a></li>

  <li><a href="http://msdn.microsoft.com/en-us/library/0580x1f5(v=vs.100).aspx/html">Implementing a Profile Provider</a></li>
</ul>

<p>These providers can contain a large number of members that must be implemented in the derived class.&#160; In the case of LightSwitch’s usage of these providers, not all the members need to be fully implemented.&#160; Here’s a list of provider members which LightSwitch uses and, thus, must be implemented (as opposed to just throwing a NotImplementedException):</p>

<ul>
  <li>MembershipProvider</li>

  <ul>
    <li>Properties</li>

    <ul>
      <li>ApplicationName</li>

      <li>MaxInvalidPasswordAttempts [Forms authentication only]</li>

      <li>MinRequiredNonAlphanumericCharacters [Forms authentication only]</li>

      <li>MinRequiredPasswordLength [Forms authentication only]</li>

      <li>PasswordFormat</li>

      <li>PasswordStrengthRegularExpression [Forms authentication only]</li>
    </ul>

    <li>Methods</li>

    <ul>
      <li>ChangePassword [Forms authentication only]</li>

      <li>CreateUser</li>

      <li>DeleteUser</li>

      <li>GetAllUsers</li>

      <li>GetUser(string, bool)</li>

      <li>ResetPassword [Forms authentication only, “answer” argument will always be null]</li>

      <li>UnlockUser</li>

      <li>ValidateUser [Forms authentication only]</li>
    </ul>
  </ul>

  <li>RoleProvider</li>

  <ul>
    <li>Properties</li>

    <ul>
      <li>ApplicationName</li>
    </ul>

    <li>Methods</li>

    <ul>
      <li>AddUsersToRoles</li>

      <li>CreateRole</li>

      <li>DeleteRole</li>

      <li>GetAllRoles</li>

      <li>GetRolesForUser</li>

      <li>GetUsersInRole</li>

      <li>RemoveUsersFromRoles</li>

      <li>RoleExists</li>
    </ul>
  </ul>

  <li>ProfileProvider [Forms authentication only]</li>

  <ul>
    <li>Properties</li>

    <ul>
      <li>ApplicationName</li>
    </ul>

    <li>Methods</li>

    <ul>
      <li>DeleteProfiles</li>

      <li>GetPropertyValues</li>

      <li>SetPropertyValues
        <br /></li>
    </ul>
  </ul>
</ul>

<h3>Wrap-up</h3>

<p>It was important within the design of LightSwitch that existing technologies were used where appropriate.&#160; In the case of user and role management, ASP.NET already provided a mechanism for this, so we didn’t reinvent the wheel and instead built LightSwitch on top of those APIs.&#160; This allows LightSwitch to be customized in a way that is not unique to LightSwitch but is a familiar experience for ASP.NET developers.</p>

<p>I encourage you to read the MSDN articles that are linked from this blog post.&#160; You can learn a lot of extra information on the APIs and provider customization from those articles.</p>

<p>Please let me know if you have any questions or run into any issues.</p>]]></content:encoded>
    </item>
    <item>
      <title>Using the SecurityData service in LightSwitch</title>
      <link>https://docs.microsoft.com/archive/blogs/mthalman/using-the-securitydata-service-in-lightswitch</link>
      <pubDate>Thu, 15 Mar 2012 13:10:47 GMT</pubDate>
      <dc:creator><![CDATA[Matt Thalman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mthalman/2012/03/15/using-the-securitydata-service-in-lightswitch/</guid>
      <description><![CDATA[In this blog post, I’m going to describe how LightSwitch developers can programmatically access the...]]></description>
      <content:encoded><![CDATA[<p>In this blog post, I’m going to describe how LightSwitch developers can programmatically access the security data contained in a LightSwitch application.&#160; Having access to this data is useful for any number of reasons.&#160; For example, you can use this API to programmatically add new users to the application.</p>  <p>This data is exposed in code as entities, just like with your own custom data.&#160; So it’s an easy and familiar API to work with.&#160; And it’s available from both client or server code.</p>  <p>First I’d like to describe the security data model.&#160; Here’s a UML diagram describing the service, entities, and supporting classes:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/2072.image_7477831B.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/2072.image_5F00_7477831B.png"><img style="border: 0px currentcolor; display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/3146.image_thumb_531A6E30.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/3146.image_5F00_thumb_5F00_531A6E30.png" width="537" height="412" /></a></p>  <p><strong><font size="2">SecurityData</font></strong></p>  <p>This is the data service class that provides access to the security entities as well as a few security-related methods.&#160; It is available from your DataWorkspace object via its SecurityData property.</p>  <p>SecurityData is a LightSwitch data service and behaves in the same way as the data service that gets generated when you add a data source to LightSwitch.&#160; It exposes the same type of query and save methods.&#160; It just operates on the built-in security entities instead of your entities.</p>  <blockquote>   <p><strong>Some important notes regarding having access to your application’s security data:        <br /></strong>In a running LightSwitch application, users which <em>do not </em>have the SecurityAdministration permission are only allowed to read security data; they cannot insert, update, or delete it.&#160; In addition, those users are only able to read security data that is relevant to themselves.&#160; So if a user named Bob, who does not have the SecurityAdministration permission, queries the UserRegistrations entity set, he will only see a UserRegistration with the name of Bob.&#160; He will not be able to see that there also exists a UserRegistration with the name of Kim since he is not logged in as Kim.&#160; Similarly with roles, if Bob queries the Roles entity set, he can see that a role named SalesPerson exists because he is assigned to that role.&#160; But he cannot see that a role named Manager exists because he is not assigned to that role.       <br />      <br />Users which <em>do</em> have the SecurityAdministration permission are not restricted in their access to security data.&#160; They are able to read all stored security data and have the ability to modify it.</p> </blockquote>  <p>In addition to entity sets, SecurityData also exposes a few useful methods:</p>  <ul>   <li>ChangePassword     <br />This method allows a user to change their own password.&#160; They need to supply their old password in order to do so.&#160; If the oldPassword parameter doesn’t match the current password or the new password doesn’t conform to the password requirements, an exception will be thrown.&#160; This method is only relevant when Forms authentication is being used.&#160; This method can be called by any user; they do not require the SecurityAdministration permission.</li>    <li>GetWindowsUserInfo     <br />This method validates and resolve a Windows account name into a normalized value and retrieve the full name (display name) of that user.&#160; As an example, let’s say that you passed “kim@contoso.com” as the parameter to this operation, it would return back a WindowsUserInfo object with the FullName property set to “Kim Abercrombie” and the NormalizedUserName property set to “contoso\kim”.&#160; If the service is unable to resolve the username parameter to a known account, an exception will be thrown.&#160; This method is only relevant when Windows authentication is being used.&#160; This method can only be called by users that have the SecurityAdministration permission.</li>    <li>IsValidPassword     <br />This method checks whether the supplied password meets the password requirements of the application.&#160; This happens automatically when attempting to add a new user or updating their password but this method allows the caller to preemptively check the password which can be useful for validation UI purposes.&#160; This method is only relevant when Forms authentication is being used.&#160; This method can only be called by users that have the SecurityAdministration permission.</li> </ul>  <p><strong><font size="2">UserRegistration</font></strong></p>  <p>The UserRegistration entity represents a user that has access to the application.&#160; (In VS 11, it can also represent an Active Directory security group when Windows authentication is being used).&#160; When using Forms authentication, all the UserRegistration properties (UserName, FullName, Password) are required.&#160; When using Windows authentication, only the UserName property is required; FullName is populated dynamically based on the UserName and Password is irrelevant.</p>  <p>Here is some example code using the UserRegistration entity:</p>  <p>C#:</p>  <div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper">   <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 128, 0);">// Create a new UserRegistration (Windows authentication)</span><br />UserRegistration user = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.UserRegistrations.AddNew();<br />user.UserName = <span style="color: rgb(0, 96, 128);">&quot;contoso\\kim&quot;</span>;<br /><span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.SaveChanges();<br /><br /><span style="color: rgb(0, 128, 0);">// Create a new UserRegistration (Forms authentication)</span><br />UserRegistration user = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.UserRegistrations.AddNew();<br />user.UserName = <span style="color: rgb(0, 96, 128);">&quot;kim_abercrombie&quot;</span>;<br />user.FullName = <span style="color: rgb(0, 96, 128);">&quot;Kim Abercrombie&quot;</span>;<br />user.Password = <span style="color: rgb(0, 96, 128);">&quot;mysecretpassword!&quot;</span>;<br /><span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.SaveChanges();<br /><br /><span style="color: rgb(0, 128, 0);">// Iterate through all UserRegistrations</span><br /><span style="color: rgb(0, 0, 255);">foreach</span> (UserRegistration user <span style="color: rgb(0, 0, 255);">in</span> <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.UserRegistrations)<br />{<br />}<br /><br /><span style="color: rgb(0, 128, 0);">// Find a specific UserRegistration (Windows authentication)</span><br />UserRegistration user = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.UserRegistrations_Single(<span style="color: rgb(0, 96, 128);">&quot;contoso\\kim&quot;</span>);<br /><br /><span style="color: rgb(0, 128, 0);">// Find a specific UserRegistration (Forms authentication)</span><br />UserRegistration user = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.UserRegistrations_Single(<span style="color: rgb(0, 96, 128);">&quot;kim_abercrombie&quot;</span>);</pre>
</div>

<p>VB:</p>

<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper">
  <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 128, 0);">' Create a new UserRegistration (Windows authentication)</span><br /><span style="color: rgb(0, 0, 255);">Dim</span> user <span style="color: rgb(0, 0, 255);">As</span> UserRegistration = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.UserRegistrations.AddNew()<br />user.UserName = <span style="color: rgb(0, 96, 128);">&quot;contoso\\kim&quot;</span><br /><span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.SaveChanges()<br /><br /><span style="color: rgb(0, 128, 0);">' Create a new UserRegistration (Forms authentication)</span><br /><span style="color: rgb(0, 0, 255);">Dim</span> user <span style="color: rgb(0, 0, 255);">As</span> UserRegistration = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.UserRegistrations.AddNew()<br />user.UserName = <span style="color: rgb(0, 96, 128);">&quot;kim_abercrombie&quot;</span><br />user.FullName = <span style="color: rgb(0, 96, 128);">&quot;Kim Abercrombie&quot;</span><br />user.Password = <span style="color: rgb(0, 96, 128);">&quot;mysecretpassword!&quot;</span><br /><span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.SaveChanges()<br /><br /><span style="color: rgb(0, 128, 0);">' Iterate through all UserRegistrations</span><br /><span style="color: rgb(0, 0, 255);">For</span> <span style="color: rgb(0, 0, 255);">Each</span> user <span style="color: rgb(0, 0, 255);">As</span> UserRegistration <span style="color: rgb(0, 0, 255);">In</span> <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.UserRegistrations<br /><span style="color: rgb(0, 0, 255);">Next</span><br /><br /><span style="color: rgb(0, 128, 0);">' Find a specific UserRegistration (Windows authentication)</span><br /><span style="color: rgb(0, 0, 255);">Dim</span> user <span style="color: rgb(0, 0, 255);">As</span> UserRegistration = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.UserRegistrations_Single(<span style="color: rgb(0, 96, 128);">&quot;contoso\\kim&quot;</span>)<br /><br /><span style="color: rgb(0, 128, 0);">' Find a specific UserRegistration (Forms authentication)</span><br /><span style="color: rgb(0, 0, 255);">Dim</span> user <span style="color: rgb(0, 0, 255);">As</span> UserRegistration = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.UserRegistrations_Single(<span style="color: rgb(0, 96, 128);">&quot;kim_abercrombie&quot;</span>)</pre>
</div>

<p><strong></strong></p>

<p><strong><font size="2">Role</font></strong></p>

<p>The Role entity represents a grouping of users with common characteristics.&#160; Examples of roles in an application include “Sales Person” and “Manager”.&#160; You can then configure your application security around these roles.</p>

<p>Here is some example code using the Role entity:</p>

<p>C#:</p>

<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper">
  <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 128, 0);">// Create a new role</span><br />Role role = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.Roles.AddNew();<br />role.Name = <span style="color: rgb(0, 96, 128);">&quot;Manager&quot;</span>;<br /><span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.SaveChanges();<br /><br /><span style="color: rgb(0, 128, 0);">// Iterate through all Roles</span><br /><span style="color: rgb(0, 0, 255);">foreach</span> (Role role <span style="color: rgb(0, 0, 255);">in</span> <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.Roles)<br />{<br />}<br /><br /><span style="color: rgb(0, 128, 0);">// Find a specific role</span><br />Role role = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.Roles_Single(<span style="color: rgb(0, 96, 128);">&quot;Manager&quot;</span>);</pre>
</div>

<p>VB:</p>

<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper">
  <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 128, 0);">' Create a new role</span><br /><span style="color: rgb(0, 0, 255);">Dim</span> role <span style="color: rgb(0, 0, 255);">As</span> Role = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.Roles.AddNew()<br />role.Name = <span style="color: rgb(0, 96, 128);">&quot;Manager&quot;</span><br /><span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.SaveChanges()<br /><br /><span style="color: rgb(0, 128, 0);">' Iterate through all Roles</span><br /><span style="color: rgb(0, 0, 255);">For</span> <span style="color: rgb(0, 0, 255);">Each</span> role <span style="color: rgb(0, 0, 255);">As</span> Role <span style="color: rgb(0, 0, 255);">In</span> <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.Roles<br /><span style="color: rgb(0, 0, 255);">Next</span><br /><br /><span style="color: rgb(0, 128, 0);">' Find a specific role</span><br /><span style="color: rgb(0, 0, 255);">Dim</span> role <span style="color: rgb(0, 0, 255);">As</span> Role = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.Roles_Single(<span style="color: rgb(0, 96, 128);">&quot;Manager&quot;</span>)</pre>
</div>

<p>&#160;</p>

<p><strong><font size="2">RoleAssignment</font></strong></p>

<p>The RoleAssignment entity represents a mapping between a Role and a UserRegistration.&#160; It is how you define that a user belongs to a role.</p>

<p>Here is some example code using the RoleAssignment entity:</p>

<p>C#</p>

<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper">
  <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 128, 0);">// Assign Kim to the Manager role</span><br />UserRegistration user = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.UserRegistrations_Single(<span style="color: rgb(0, 96, 128);">&quot;contoso\\kim&quot;</span>);<br />Role role = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.Roles_Single(<span style="color: rgb(0, 96, 128);">&quot;Manager&quot;</span>);<br />RoleAssignment roleAssignment = user.RoleAssignments.AddNew();<br />roleAssignment.Role = role;<br /><span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.SaveChanges();<br /><br /><span style="color: rgb(0, 128, 0);">// Find which roles Kim is assigned to</span><br />UserRegistration user = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.UserRegistrations_Single(<span style="color: rgb(0, 96, 128);">&quot;contoso\\kim&quot;</span>);<br /><span style="color: rgb(0, 0, 255);">foreach</span> (RoleAssignment roleAssignment <span style="color: rgb(0, 0, 255);">in</span> user.RoleAssignments)<br />{<br />    Role role = roleAssignment.Role;<br />}</pre>
</div>

<p>VB:</p>

<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper">
  <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 128, 0);">' Assign Kim to the Manager role</span><br /><span style="color: rgb(0, 0, 255);">Dim</span> user <span style="color: rgb(0, 0, 255);">As</span> UserRegistration = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.UserRegistrations_Single(<span style="color: rgb(0, 96, 128);">&quot;contoso\\kim&quot;</span>)<br /><span style="color: rgb(0, 0, 255);">Dim</span> role <span style="color: rgb(0, 0, 255);">As</span> Role = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.Roles_Single(<span style="color: rgb(0, 96, 128);">&quot;Manager&quot;</span>)<br /><span style="color: rgb(0, 0, 255);">Dim</span> roleAssignment <span style="color: rgb(0, 0, 255);">As</span> RoleAssignment = user.RoleAssignments.AddNew()<br />roleAssignment.Role = role<br /><span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.SaveChanges()<br /><br /><span style="color: rgb(0, 128, 0);">' Find which roles Kim is assigned to</span><br /><span style="color: rgb(0, 0, 255);">Dim</span> user <span style="color: rgb(0, 0, 255);">As</span> UserRegistration = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.UserRegistrations_Single(<span style="color: rgb(0, 96, 128);">&quot;contoso\\kim&quot;</span>)<br /><span style="color: rgb(0, 0, 255);">For</span> <span style="color: rgb(0, 0, 255);">Each</span> roleAssignment <span style="color: rgb(0, 0, 255);">As</span> RoleAssignment <span style="color: rgb(0, 0, 255);">In</span> user.RoleAssignments<br />    <span style="color: rgb(0, 0, 255);">Dim</span> role <span style="color: rgb(0, 0, 255);">As</span> Role = roleAssignment.Role<br />Next</pre>
</div>

<p>&#160;</p>

<p><strong><font size="2">Permission</font></strong></p>

<p>The Permission entity represents an action that a logged in user is permitted to do within the application.&#160; Examples of permissions in an application include “CanRejectSalesOrder” and “CanUpdateInventory”.&#160; Permissions are different than the rest of the security data because they are read-only.&#160; The permissions that are available map to the permissions that were defined within the Access Control tab of the application properties of a LightSwitch project:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/6170.image_37E4A5E0.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/6170.image_5F00_37E4A5E0.png"><img style="border: 0px currentcolor; display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5773.image_thumb_3E2B7C6E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/5773.image_5F00_thumb_5F00_3E2B7C6E.png" width="536" height="114" />&#160;</a></p>

<p>Here is some example code using the Permission entity:</p>

<p>C#:</p>

<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper">
  <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 128, 0);">// Iterate through all Permissions</span><br /><span style="color: rgb(0, 0, 255);">foreach</span> (Permission permission <span style="color: rgb(0, 0, 255);">in</span> <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.Permissions)<br />{<br />}<br /><br /><span style="color: rgb(0, 128, 0);">// Find a specific Permission</span><br />Permission permission = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.Permissions_Single(Permissions.CanRejectSalesOrder);</pre>
</div>

<p>VB:</p>

<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper">
  <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 128, 0);">' Iterate through all Permissions</span><br /><span style="color: rgb(0, 0, 255);">For</span> <span style="color: rgb(0, 0, 255);">Each</span> permission <span style="color: rgb(0, 0, 255);">As</span> Permission <span style="color: rgb(0, 0, 255);">In</span> <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.Permissions<br /><span style="color: rgb(0, 0, 255);">Next</span><br /><br /><span style="color: rgb(0, 128, 0);">' Find a specific Permission</span><br /><span style="color: rgb(0, 0, 255);">Dim</span> permission <span style="color: rgb(0, 0, 255);">As</span> Permission = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.Permissions_Single(Permissions.CanRejectSalesOrder)</pre>
</div>

<p>&#160;</p>

<p><strong><font size="2">RolePermission</font></strong></p>

<p>The RolePermission entity represents a mapping between a Role and a Permission.&#160; It is how you define that a permission is assigned to a role.</p>

<p>Here is some example code using the RolePermission entity:</p>

<p>C#:</p>

<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper">
  <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 128, 0);">// Assign CanRejectSalesOrder permission to Manager role</span><br />Role role = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.Roles_Single(<span style="color: rgb(0, 96, 128);">&quot;Manager&quot;</span>);<br />Permission permission = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.Permissions_Single(Permissions.CanRejectSalesOrder);<br />RolePermission rolePermission = role.RolePermissions.AddNew();<br />rolePermission.Permission = permission;<br /><span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.SaveChanges();<br /><br /><span style="color: rgb(0, 128, 0);">// Find which permissions are assigned to the Manager role</span><br />Role role = <span style="color: rgb(0, 0, 255);">this</span>.DataWorkspace.SecurityData.Roles_Single(<span style="color: rgb(0, 96, 128);">&quot;Manager&quot;</span>);<br /><span style="color: rgb(0, 0, 255);">foreach</span> (RolePermission rolePermission <span style="color: rgb(0, 0, 255);">in</span> role.RolePermissions)<br />{<br />    Permission permission = rolePermission.Permission;<br />}</pre>
</div>

<p>VB:</p>

<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper">
  <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"><span style="color: rgb(0, 128, 0);">' Assign CanRejectSalesOrder permission to Manager role</span><br /><span style="color: rgb(0, 0, 255);">Dim</span> role <span style="color: rgb(0, 0, 255);">As</span> Role = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.Roles_Single(<span style="color: rgb(0, 96, 128);">&quot;Manager&quot;</span>)<br /><span style="color: rgb(0, 0, 255);">Dim</span> permission <span style="color: rgb(0, 0, 255);">As</span> Permission = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.Permissions_Single(Permissions.CanRejectSalesOrder)<br /><span style="color: rgb(0, 0, 255);">Dim</span> rolePermission <span style="color: rgb(0, 0, 255);">As</span> RolePermission = role.RolePermissions.AddNew()<br />rolePermission.Permission = permission<br /><span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.SaveChanges()<br /><br /><span style="color: rgb(0, 128, 0);">' Find which permissions are assigned to the Manager role</span><br /><span style="color: rgb(0, 0, 255);">Dim</span> role <span style="color: rgb(0, 0, 255);">As</span> Role = <span style="color: rgb(0, 0, 255);">Me</span>.DataWorkspace.SecurityData.Roles_Single(<span style="color: rgb(0, 96, 128);">&quot;Manager&quot;</span>)<br /><span style="color: rgb(0, 0, 255);">For</span> <span style="color: rgb(0, 0, 255);">Each</span> rolePermission <span style="color: rgb(0, 0, 255);">As</span> RolePermission <span style="color: rgb(0, 0, 255);">In</span> role.RolePermissions<br />    <span style="color: rgb(0, 0, 255);">Dim</span> permission <span style="color: rgb(0, 0, 255);">As</span> Permission = rolePermission.Permission<br />Next</pre>
</div>

<p>&#160;</p>

<p><strong><font size="2">Conclusion</font></strong></p>

<p>Using the SecurityData service and the entities it exposes, you can accomplish all kinds of interesting scenarios that require dynamic management of your application’s security data.&#160; I hope you’ve found this blog post helpful in your work.&#160; Happy coding.</p>]]></content:encoded>
    </item>
    <item>
      <title>Controlling App Capabilities when Using Shared Libraries in Windows Phone Apps</title>
      <link>https://docs.microsoft.com/archive/blogs/mthalman/controlling-app-capabilities-when-using-shared-libraries-in-windows-phone-apps</link>
      <pubDate>Tue, 21 Feb 2012 06:37:00 GMT</pubDate>
      <dc:creator><![CDATA[Matt Thalman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mthalman/2012/02/21/controlling-app-capabilities-when-using-shared-libraries-in-windows-phone-apps/</guid>
      <description><![CDATA[The Problem:
The other day I published an updated version of my Windows Phone app CalcuFitness...]]></description>
      <content:encoded><![CDATA[<p><strong>The Problem:</strong></p>
<p>The other day I published an updated version of my Windows Phone app <a href="http://www.windowsphone.com/en-US/apps/0873ba67-d56e-e011-81d2-78e7d1fa76f8">CalcuFitness</a> after some major code refactoring.&nbsp; Much to my surprise, I discovered that the app certification process determined that my app required the location services capability when it in fact does not make use of location services.&nbsp; It wasn&rsquo;t long before I realized what caused this.</p>
<p>I have several Windows Phone apps in development and, being a good developer, I try to share as much code between them as I can.&nbsp; So I create common library projects that many of my apps reference.&nbsp; Well, one of my apps did need to use location service functionality and I decided to put some of that functionality into one of the common libraries because it was general purpose enough to be used by other apps.&nbsp; Well, my CalcuFitness app referenced that library and compiled that code into its binary.</p>
<p>When you submit your app to the Marketplace, they automatically scan your binary looking to see whether you use certain APIs to determine what app capabilities are required.&nbsp; Since my app&rsquo;s binary contained code that referenced an API associated with location services, the system marked my app as requiring that capability.&nbsp; It doesn&rsquo;t matter whether there&rsquo;s a code path in my app that actually makes use of that API.</p>
<p><strong>The Solution:</strong></p>
<p>The way I went about solving this problem was to make use of conditional symbols and build configurations in Visual Studio to control the code that actually gets compiled for my phone app.&nbsp; First, I define a conditional symbol for each of the capabilities that my code makes use of and wrap that code within #if&hellip;#endif preprocessing directives.&nbsp; In my case, I created a LOCATION_SERVICE_CAPABILITY symbol and added it to my code like this:</p>
<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: 'Courier New', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;" id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;" id="codeSnippet"><span style="color: #cc6633;">#if</span> LOCATION_SERVICE_CAPABILITY<br />    <span style="color: #008000;">// my location service code</span><br /><span style="color: #cc6633;">#endif</span></pre>
</div>
<p>Ok, so now this code will only be compiled if the project is built with the LOCATION_SERVICE_CAPABILITY symbol.&nbsp; By default, my app will not compile this code since it&rsquo;s not configured to have the LOCATION_SERVICE_CAPABILITY symbol defined.</p>
<p>Now let&rsquo;s say that I have another app &ndash; let&rsquo;s call it &ldquo;MyLocationPhoneApp&rdquo; &ndash; where I do want this location service functionality to be used.&nbsp; I can&rsquo;t just set the LOCATION_SERVICE_CAPABILITY symbol for the Debug and Retail build configurations because that would cause this code to be compiled into all my phone apps that reference this project.&nbsp; Instead, I&rsquo;m going to create a specific build configuration for my app.&nbsp; To do this, I do the following:</p>
<ol>
<li>Open the project file of my library.</li>
<li>Create a new build configuration by copying the Debug and/or Release configuration.</li>
<li>Change the name of this new configuration by including the name of the phone app which references this library.</li>
<li>Include additional symbol names in the DefineConstants that correlate to the symbols defined in the library that are used by the app.</li>
</ol>
<p>For example, here&rsquo;s the Debug configuration I created with the important parts highlighted:</p>
<div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: 'Courier New', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;" id="codeSnippetWrapper">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">PropertyGroup</span> <span style="color: #ff0000;">Condition</span><span style="color: #0000ff;">=" '$(Configuration)|$(Platform)' == '<span style="background-color: #ffff00;">MyLocationPhoneApp_Debug</span>|AnyCPU' "</span><span style="color: #0000ff;">&gt;</span><br />  <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">DebugSymbols</span><span style="color: #0000ff;">&gt;</span>true<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">DebugSymbols</span><span style="color: #0000ff;">&gt;</span><br />  <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">DebugType</span><span style="color: #0000ff;">&gt;</span>full<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">DebugType</span><span style="color: #0000ff;">&gt;</span><br />  <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Optimize</span><span style="color: #0000ff;">&gt;</span>false<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">Optimize</span><span style="color: #0000ff;">&gt;</span><br />  <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">OutputPath</span><span style="color: #0000ff;">&gt;</span>Bin\Debug<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">OutputPath</span><span style="color: #0000ff;">&gt;</span><br />  <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">DefineConstants</span><span style="color: #0000ff;">&gt;</span>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE;<span style="background-color: #ffff00;">LOCATION_SERVICE_CAPABILITY</span><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">DefineConstants</span><span style="color: #0000ff;">&gt;</span><br /><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">PropertyGroup</span><span style="color: #0000ff;">&gt;</span></pre>
</div>
<p>I actually do this for both Debug and Release to ensure that I can build with the constant in either mode. Whenever this project is built using this build configuration, the location service-related code will be included in the compilation.&nbsp; Ok, that&rsquo;s good but I&rsquo;m not done yet.</p>
<p>Next I need to open up Configuration Manager (Build &ndash;&gt; Configuration Manager) in Visual Studio.&nbsp; This window allows me to define which build configuration to use for each of the projects in my solution.&nbsp; So when my solution is configured to build Debug, I configure my library project to build with the &ldquo;MyLocationPhoneApp_Debug&rdquo; configuration.</p>
<p>And I follow this pattern for each app that references this library project.&nbsp; Essentially, the build configuration let&rsquo;s me create an app profile that defines which capabilities should be exposed by the library.&nbsp; This prevents code which impacts the phone capability requirements from entering into my app&rsquo;s binary if it doesn&rsquo;t require that capability.</p>]]></content:encoded>
    </item>
    <item>
      <title>LightSwitch Trick: Display Loading Message while a Screen is Loading</title>
      <link>https://docs.microsoft.com/archive/blogs/mthalman/lightswitch-trick-display-loading-message-while-a-screen-is-loading</link>
      <pubDate>Wed, 15 Feb 2012 12:42:27 GMT</pubDate>
      <dc:creator><![CDATA[Matt Thalman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mthalman/2012/02/15/lightswitch-trick-display-loading-message-while-a-screen-is-loading/</guid>
      <description><![CDATA[In the LightSwitch apps that I create, I have a common pattern where I display a “Loading” message...]]></description>
      <content:encoded><![CDATA[<p>In the LightSwitch apps that I create, I have a common pattern where I display a “Loading” message in the title bar of a screen while it is loading and then set it to its actual screen name once it’s finished.&#160; In particular, this is useful for screens whose title is dependent on the data that is loaded by the screen, such as a customer detail screen whose title is the name of the customer.</p>  <p>This is just a nice little tweak to the UI that’s quite simple to implement.&#160; Here’s how:</p>  <p>Ensure that focus is set to your screen’s content tree and choose the InitializeDataWorkspace event from the Write Code dropdown button:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/4572.image_3982AF4F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/4572.image_5F00_3982AF4F.png"><img style="border: 0px currentcolor; display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/7888.image_thumb_21152CA3.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/7888.image_5F00_thumb_5F00_21152CA3.png" width="305" height="235" /></a></p>  <p>In the method stub that gets generated, add the following code (replacing CustomerDetail with your actual screen name):</p>  <p>C#:</p>  <pre class="code"><span style="color: blue;">partial void </span>CustomerDetail_InitializeDataWorkspace(<br />  <span style="color: rgb(43, 145, 175);">List</span>&lt;<span style="color: rgb(43, 145, 175);">IDataService</span>&gt; saveChangesTo)
{
    <span style="color: blue;">this</span>.DisplayName = <span style="color: rgb(163, 21, 21);">&quot;Loading...&quot;</span>;
}
</pre>

<p>VB:</p>

<pre class="code"><span style="color: blue;">Private Sub </span>CustomerDetail_InitializeDataWorkspace(saveChangesTo _<br />  <span style="color: blue;">As </span>System.Collections.Generic.<span style="color: rgb(43, 145, 175);">List</span>(<span style="color: blue;">Of </span>Microsoft.LightSwitch.<span style="color: rgb(43, 145, 175);">IDataService</span>))
    <span style="color: blue;">Me</span>.DisplayName = <span style="color: rgb(163, 21, 21);">&quot;Loading...&quot;
</span><span style="color: blue;">End Sub
</span></pre>

<p>&#160;</p>

<p>And that’s all you have to do if you are using a Details screen template.&#160; That’s because for a Details screen, LightSwitch automatically generates code for the entity property’s Loaded event to update the display name based on the entity’s data.</p>

<p>The InitializeDataWorkspace event is used because that’s the very first event that the screen raises.&#160; So within that event, the screen’s display name is immediately set to “Loading…”.&#160; Then, once the data is loaded, code runs in the Loaded event that explicitly sets the screen’s display name to the desired value.</p>

<p>If you wanted to apply this technique to a non-Details screen, you would do the same thing as above but additionally you would need to implement the Loaded event for one of your screen’s entity or collection properties that would set the DisplayName of the screen.&#160; For example, here’s how I’ve done it for my Customers Grid screen:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/6712.image_37D704DD.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/6712.image_5F00_37D704DD.png"><img style="border: 0px currentcolor; display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/8867.image_thumb_32F45121.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/8867.image_5F00_thumb_5F00_32F45121.png" width="392" height="191" /></a></p>

<p>C#:</p>

<pre class="code"><span style="color: blue;">partial void </span>Customers_Loaded(<span style="color: blue;">bool </span>succeeded)
{
    <span style="color: blue;">this</span>.DisplayName = <span style="color: rgb(163, 21, 21);">&quot;Customers&quot;</span>;
}
</pre>

<p>VB:</p>

<pre class="code"><span style="color: blue;">Private Sub </span>Customers_Loaded(succeeded <span style="color: blue;">As Boolean</span>)
    <span style="color: blue;">Me</span>.DisplayName = <span style="color: rgb(163, 21, 21);">&quot;Customers&quot;
</span><span style="color: blue;">End Sub
</span></pre>

<p>&#160;</p>

<p>The end result is that you see this while the screen is loading:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5635.image_0DF690A8.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/5635.image_5F00_0DF690A8.png"><img style="border: 0px currentcolor; display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/8030.image_thumb_2B6B7265.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/8030.image_5F00_thumb_5F00_2B6B7265.png" width="400" height="178" /></a></p>

<p>and this once it’s finished loading:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/3568.image_7FBAA868.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/3568.image_5F00_7FBAA868.png"><img style="border: 0px currentcolor; display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/1106.image_thumb_2FE483DD.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/1106.image_5F00_thumb_5F00_2FE483DD.png" width="383" height="158" /></a></p>]]></content:encoded>
    </item>
    <item>
      <title>Creating a Custom Login Page for a LightSwitch Application</title>
      <link>https://docs.microsoft.com/archive/blogs/mthalman/creating-a-custom-login-page-for-a-lightswitch-application</link>
      <pubDate>Thu, 08 Dec 2011 06:06:08 GMT</pubDate>
      <dc:creator><![CDATA[Matt Thalman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mthalman/2011/12/08/creating-a-custom-login-page-for-a-lightswitch-application/</guid>
      <description><![CDATA[When configuring a Visual Studio LightSwitch application to use Forms authentication, the...]]></description>
      <content:encoded><![CDATA[<p>When configuring a Visual Studio LightSwitch application to use Forms authentication, the application user is prompted with the following login UI when they open the application:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/2548.originallogin_31BD92BC.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/2548.originallogin_5F00_31BD92BC.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="original-login" border="0" alt="original-login" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/7725.originallogin_thumb_711B464C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/7725.originallogin_5F00_thumb_5F00_711B464C.png" width="383" height="280" /></a> </p>  <p></p>  <p>Many LightSwitch customers have asked about creating their own custom UI in place of this default login experience.&#160; Maybe you’d like to display the company logo, for example.&#160; This post will show you the steps for creating your own fully customizable login page.</p>  <p>LightSwitch doesn’t have not have <em>built-in</em> support for customizing this UI.&#160; However, since LightSwitch is an ASP-NET based application you can use the features in ASP.NET to workaround this.&#160; What I’m going to demonstrate here is how to create an ASPX page that will authenticate the user when they open the app.&#160; Since you write the content of the ASPX page, you get to control exactly how it looks to the user.&#160; But I’ll make it easy for you by providing some sample markup that you can use and customize.</p>  <p><strong>NOTE:      <br />These instructions are for creating a custom login page for Web-based LightSwitch applications (meaning, the application is hosted within the browser).&#160; There isn’t a way to create a custom login page for a Desktop LightSwitch application.&#160; In addition, these instructions assume that you have Visual Studio Professional or higher installed in addition to LightSwitch.&#160; This isn’t necessarily required, but it makes the task of adding ASPX files to the project simpler; otherwise, you’d have to do this by hand which I won’t be describing in this post.</strong></p>  <p>First, let’s start with a brand new LightSwitch project and open up the application properties window:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/6735.openappproperties_3078F9DD.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/6735.openappproperties_5F00_3078F9DD.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="open-app-properties" border="0" alt="open-app-properties" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/1464.openappproperties_thumb_76F5E9E5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/1464.openappproperties_5F00_thumb_5F00_76F5E9E5.png" width="306" height="126" /></a> </p>  <p>In the application properties window, select the Access Control tab and enable Forms authentication:</p>  <p></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/6735.enableformsauth_122E42E7.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/6735.enableformsauth_5F00_122E42E7.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="enable-forms-auth" border="0" alt="enable-forms-auth" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/0486.enableformsauth_thumb_55964449.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/0486.enableformsauth_5F00_thumb_5F00_55964449.png" width="470" height="183" /></a> </p>  <p>Select the Application Type tab and change the client type to Web:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/2134.webapptype_50B3908D.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/2134.webapptype_5F00_50B3908D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="web-app-type" border="0" alt="web-app-type" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5672.webapptype_thumb_141B91F0.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/5672.webapptype_5F00_thumb_5F00_141B91F0.png" width="467" height="315" /></a> </p>  <p>Now switch Solution Explorer into File View in order to manage the physical files that make up a LightSwitch application:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/4682.switchtofileview_2834AE79.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/4682.switchtofileview_5F00_2834AE79.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="switch-to-file-view" border="0" alt="switch-to-file-view" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/0486.switchtofileview_thumb_6EB19E81.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/0486.switchtofileview_5F00_thumb_5F00_6EB19E81.png" width="317" height="144" /></a>&#160;</p>  <p>Next, click the “Show All Files” toolbar button.&#160; This shows all the hidden files within the project.</p>  <p></p>  <p></p> <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/8802.showallfiles_6006F29C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/8802.showallfiles_5F00_6006F29C.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="show-all-files" border="0" alt="show-all-files" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/1882.showallfiles_thumb_587B832F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/1882.showallfiles_5F00_thumb_5F00_587B832F.png" width="319" height="188" /></a>   <p>This is what the resulting project looks like now:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/7840.expandedproject_5EC259BD.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/7840.expandedproject_5F00_5EC259BD.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="expanded-project" border="0" alt="expanded-project" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/3531.expandedproject_thumb_7032BA95.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/3531.expandedproject_5F00_thumb_5F00_7032BA95.png" width="321" height="258" /></a> </p>  <p>Add a new ASPX page to the ServerGenerated project by selecting the ServerGenerated project and hit Ctrl+Shift+A.&#160; Then select “Web Form” from the Web node and change the filename to “Home.aspx”.&#160; Click the Add button.&#160; </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/4201.addloginpage_3D62B421.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/4201.addloginpage_5F00_3D62B421.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="add-login-page" border="0" alt="add-login-page" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/8420.addloginpage_thumb_0A267AB8.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/8420.addloginpage_5F00_thumb_5F00_0A267AB8.png" width="575" height="325" /></a> </p>  <p>Follow the same steps again to add another ASPX file but name this one “Login.aspx”.&#160; You should now have two ASPX files in your ServerGenerated project:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/6685.homeandlogin_0D5862A0.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/6685.homeandlogin_5F00_0D5862A0.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="home-and-login" border="0" alt="home-and-login" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/6114.homeandlogin_thumb_21717F29.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/6114.homeandlogin_5F00_thumb_5F00_21717F29.png" width="310" height="373" /></a> </p>  <p>Open Login.aspx and paste over the existing markup with the following:</p>  <p><strong>C#:</strong></p>  <pre class="code"><span style="background: yellow">&lt;%</span><span style="color: blue">@ </span><span style="color: maroon">Page </span><span style="color: red">Title</span><span style="color: blue">=&quot;Log In&quot; </span><span style="color: red">Language</span><span style="color: blue">=&quot;C#&quot; </span><span style="color: red">AutoEventWireup</span><span style="color: blue">=&quot;true&quot;
    </span><span style="color: red">CodeBehind</span><span style="color: blue">=&quot;Login.aspx.cs&quot; </span><span style="color: red">Inherits</span><span style="color: blue">=&quot;LightSwitchApplication.Login&quot; </span><span style="background: yellow">%&gt;

</span><span style="color: blue">&lt;</span><span style="color: maroon">form </span><span style="color: red">id</span><span style="color: blue">=&quot;Form1&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;&gt;
  &lt;</span><span style="color: maroon">div </span><span style="color: red">style</span><span style="color: blue">=&quot;</span><span style="color: red">text-align</span><span style="color: blue">:center&quot;&gt;
   </span><span style="color: #006400">&lt;!— Add an optional image by replacing this fake image URL with your own –&gt;</span>
<span style="color: #006400">   &lt;!--&lt;asp:Image runat=&quot;server&quot; ImageUrl=&quot;http://contoso.com/logo.gif&quot; /&gt;--&gt;</span><span style="color: blue">
   &lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Login </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">BackColor</span><span style="color: blue">=&quot;#F7F6F3&quot;
           </span><span style="color: red">BorderColor</span><span style="color: blue">=&quot;#E6E2D8&quot; </span><span style="color: red">BorderPadding</span><span style="color: blue">=&quot;4&quot;
           </span><span style="color: red">BorderStyle</span><span style="color: blue">=&quot;Solid&quot; </span><span style="color: red">BorderWidth</span><span style="color: blue">=&quot;1px&quot;
           </span><span style="color: red">Font-Names</span><span style="color: blue">=&quot;Verdana&quot; </span><span style="color: red">Font-Size</span><span style="color: blue">=&quot;0.8em&quot;
           </span><span style="color: red">ForeColor</span><span style="color: blue">=&quot;#333333&quot;&gt;
       &lt;</span><span style="color: maroon">InstructionTextStyle </span><span style="color: red">Font-Italic</span><span style="color: blue">=&quot;True&quot; </span><span style="color: red">ForeColor</span><span style="color: blue">=&quot;Black&quot; /&gt;
       &lt;</span><span style="color: maroon">LoginButtonStyle </span><span style="color: red">BackColor</span><span style="color: blue">=&quot;#FFFBFF&quot; </span><span style="color: red">BorderColor</span><span style="color: blue">=&quot;#CCCCCC&quot;
           </span><span style="color: red">BorderStyle</span><span style="color: blue">=&quot;Solid&quot; </span><span style="color: red">BorderWidth</span><span style="color: blue">=&quot;1px&quot; </span><span style="color: red">Font-Names</span><span style="color: blue">=&quot;Verdana&quot;
           </span><span style="color: red">Font-Size</span><span style="color: blue">=&quot;0.8em&quot; </span><span style="color: red">ForeColor</span><span style="color: blue">=&quot;#284775&quot; /&gt;
       &lt;</span><span style="color: maroon">TextBoxStyle </span><span style="color: red">Font-Size</span><span style="color: blue">=&quot;0.8em&quot; /&gt;
       &lt;</span><span style="color: maroon">TitleTextStyle </span><span style="color: red">BackColor</span><span style="color: blue">=&quot;#5D7B9D&quot; </span><span style="color: red">Font-Bold</span><span style="color: blue">=&quot;True&quot;
           </span><span style="color: red">Font-Size</span><span style="color: blue">=&quot;0.9em&quot; </span><span style="color: red">ForeColor</span><span style="color: blue">=&quot;White&quot; /&gt;
   &lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Login</span><span style="color: blue">&gt;
 &lt;/</span><span style="color: maroon">div</span><span style="color: blue">&gt;
&lt;/</span><span style="color: maroon">form</span><span style="color: blue">&gt;
</span></pre>
<a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a>

<p><strong>VB:</strong></p>

<pre class="code"><span style="background: yellow">&lt;%</span><span style="color: blue">@ </span><span style="color: maroon">Page </span><span style="color: red">Title</span><span style="color: blue">=&quot;Log In&quot; </span><span style="color: red">Language</span><span style="color: blue">=&quot;vb&quot; </span><span style="color: red">AutoEventWireup</span><span style="color: blue">=&quot;true&quot;
    </span><span style="color: red">CodeBehind</span><span style="color: blue">=&quot;Login.aspx.vb&quot; </span><span style="color: red">Inherits</span><span style="color: blue">=&quot;.Login&quot; </span><span style="background: yellow">%&gt;

</span><span style="color: blue">&lt;</span><span style="color: maroon">form </span><span style="color: red">id</span><span style="color: blue">=&quot;Form1&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;&gt;
  &lt;</span><span style="color: maroon">div </span><span style="color: red">style</span><span style="color: blue">=&quot;</span><span style="color: red">text-align</span><span style="color: blue">:center&quot;&gt;
   </span><span style="color: #006400">&lt;!— Add an optional image by replacing this fake image URL with your own –&gt;</span>
<span style="color: #006400">   &lt;!--&lt;asp:Image runat=&quot;server&quot; ImageUrl=&quot;http://contoso.com/logo.gif&quot; /&gt;--&gt;</span><span style="color: blue">
   &lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Login </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">BackColor</span><span style="color: blue">=&quot;#F7F6F3&quot;
           </span><span style="color: red">BorderColor</span><span style="color: blue">=&quot;#E6E2D8&quot; </span><span style="color: red">BorderPadding</span><span style="color: blue">=&quot;4&quot;
           </span><span style="color: red">BorderStyle</span><span style="color: blue">=&quot;Solid&quot; </span><span style="color: red">BorderWidth</span><span style="color: blue">=&quot;1px&quot;
           </span><span style="color: red">Font-Names</span><span style="color: blue">=&quot;Verdana&quot; </span><span style="color: red">Font-Size</span><span style="color: blue">=&quot;0.8em&quot;
           </span><span style="color: red">ForeColor</span><span style="color: blue">=&quot;#333333&quot;&gt;
       &lt;</span><span style="color: maroon">InstructionTextStyle </span><span style="color: red">Font-Italic</span><span style="color: blue">=&quot;True&quot; </span><span style="color: red">ForeColor</span><span style="color: blue">=&quot;Black&quot; /&gt;
       &lt;</span><span style="color: maroon">LoginButtonStyle </span><span style="color: red">BackColor</span><span style="color: blue">=&quot;#FFFBFF&quot; </span><span style="color: red">BorderColor</span><span style="color: blue">=&quot;#CCCCCC&quot;
           </span><span style="color: red">BorderStyle</span><span style="color: blue">=&quot;Solid&quot; </span><span style="color: red">BorderWidth</span><span style="color: blue">=&quot;1px&quot; </span><span style="color: red">Font-Names</span><span style="color: blue">=&quot;Verdana&quot;
           </span><span style="color: red">Font-Size</span><span style="color: blue">=&quot;0.8em&quot; </span><span style="color: red">ForeColor</span><span style="color: blue">=&quot;#284775&quot; /&gt;
       &lt;</span><span style="color: maroon">TextBoxStyle </span><span style="color: red">Font-Size</span><span style="color: blue">=&quot;0.8em&quot; /&gt;
       &lt;</span><span style="color: maroon">TitleTextStyle </span><span style="color: red">BackColor</span><span style="color: blue">=&quot;#5D7B9D&quot; </span><span style="color: red">Font-Bold</span><span style="color: blue">=&quot;True&quot;
           </span><span style="color: red">Font-Size</span><span style="color: blue">=&quot;0.9em&quot; </span><span style="color: red">ForeColor</span><span style="color: blue">=&quot;White&quot; /&gt;
   &lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Login</span><span style="color: blue">&gt;
 &lt;/</span><span style="color: maroon">div</span><span style="color: blue">&gt;
&lt;/</span><span style="color: maroon">form</span><span style="color: blue">&gt;
</span></pre>

<p>For more details on how to customize the Login control to suit your needs, see the following MSDN article: <a href="http://msdn.microsoft.com/en-us/library/ms178339.aspx">Customizing the Appearance of ASP.NET Login Controls</a>.</p>

<p>For the Home.aspx page, you can leave the default markup code since this page will never be visible by the user.&#160; We’re only going to use it as a redirection mechanism.</p>

<blockquote>
  <p>NOTE: 
    <br />This redirection logic is only needed to workaround an issue in LightSwitch V1 where it will remove from the web.config file at publish-time a configuration setting that will deny anonymous users access.&#160;&#160; If you have the ability to modify your web.config file after the app has been published, you can configure it to deny anonymous users by adding the following to the system.web section of the web.config file:</p>

  <pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">authorization</span><span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">deny </span><span style="color: red">users</span><span style="color: blue">=</span>&quot;<span style="color: blue">?</span>&quot;<span style="color: blue">/&gt;
&lt;/</span><span style="color: #a31515">authorization</span><span style="color: blue">&gt;</span></pre>
  <a href="http://11011.net/software/vspaste"></a>

  <p>If you end up doing this, the Home page described in this blog post would not be necessary within your site.</p>
</blockquote>

<p>To setup the redirection logic, open up the code-behind for the Home page, Home.aspx.cs, and replace its contents with the following code:</p>

<p><strong>C#:</strong></p>

<pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.Web.Security;

<span style="color: blue">namespace </span>LightSwitchApplication
{
    <span style="color: blue">public partial class </span><span style="color: #2b91af">Home </span>: System.Web.UI.<span style="color: #2b91af">Page
    </span>{
        <span style="color: blue">protected void </span>Page_Load(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e)
        {
            <span style="color: blue">if </span>(!<span style="color: blue">this</span>.User.Identity.IsAuthenticated)
            {
                <span style="color: #2b91af">FormsAuthentication</span>.RedirectToLoginPage();
            }
            <span style="color: blue">else
            </span>{
                <span style="color: blue">this</span>.Response.Redirect(<span style="color: #2b91af">FormsAuthentication</span>.DefaultUrl);
            }
        }
    }
}</pre>

<p><strong>VB:</strong></p>

<pre class="code"><span style="color: blue">Imports </span>System.Web.Security

<span style="color: blue">Public Class <font color="#333333">Home</font></span>
    <span style="color: blue">Inherits </span>System.Web.UI.<span style="color: #2b91af">Page<br /></span>
<br /><br /><br />    <span style="color: blue">Protected Sub </span>Page_Load(<span style="color: blue">ByVal </span>sender <span style="color: blue">As Object</span>,
                            <span style="color: blue">ByVal </span>e <span style="color: blue">As </span>System.<span style="color: #2b91af">EventArgs</span>) _
                        <span style="color: blue">Handles </span><span style="color: blue">Me.</span><font color="#333333">Load</font>
        <span style="color: blue">If Not </span><span style="color: blue">Me</span>.User.Identity.IsAuthenticated <font color="#0000ff">Then</font>
            <span style="color: #2b91af">FormsAuthentication</span>.RedirectToLoginPage()
        <span style="color: blue">Else</span>
            <span style="color: blue">Me</span>.Response.Redirect(<span style="color: #2b91af">FormsAuthentication</span>.DefaultUrl)
        <span style="color: blue">End If</span>
    <span style="color: blue">End Sub<br /></span>
<span style="color: blue">End Class</span></pre>

<p>Next, we need to configure the default page for the site to use this new Home page.&#160; Open the web.config file contained in the ServerGenerated folder.&#160; It will have a section that looks like this:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">defaultDocument</span><span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">files</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">clear </span><span style="color: blue">/&gt;
    &lt;</span><span style="color: #a31515">add </span><span style="color: red">value</span><span style="color: blue">=</span>&quot;<span style="color: blue">default.htm</span>&quot; <span style="color: blue">/&gt;
  &lt;/</span><span style="color: #a31515">files</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">defaultDocument</span><span style="color: blue">&gt;</span></pre>

<p><a href="http://11011.net/software/vspaste"></a>To configure the new default page, change “default.htm” to “Home.aspx”.</p>

<p>In addition, we need to configure default.htm to be the page that is redirected to after a successful login.&#160; To do this, find the forms element in the web.config file and add the bolded text:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">authentication </span><span style="color: red">mode</span><span style="color: blue">=</span>&quot;<span style="color: blue">Forms</span>&quot;<span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">forms </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">CustomLoginApp</span>&quot; <strong><span style="color: red">defaultUrl</span><span style="color: blue">=</span>&quot;<span style="color: blue">default.htm</span>&quot;</strong> <span style="color: blue">/&gt;
&lt;/</span><span style="color: #a31515">authentication</span><span style="color: blue">&gt;</span></pre>
<a href="http://11011.net/software/vspaste"></a>

<p></p>

<p></p>

<p>The last step is to configure the main LightSwitch project to be aware of the new ASPX files that were added so that they will be published along with the app. To do this, unload the main LightSwitch project:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/2061.unloadproject_12C6D344.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/2061.unloadproject_5F00_12C6D344.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="unload-project" border="0" alt="unload-project" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/2480.unloadproject_thumb_67160947.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/2480.unloadproject_5F00_thumb_5F00_67160947.png" width="312" height="295" /></a></p>

<p>With the project unloaded, open the physical .LSPROJ file in the IDE:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5125.editunloadedproject_586B5D62.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/5125.editunloadedproject_5F00_586B5D62.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="edit-unloaded-project" border="0" alt="edit-unloaded-project" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/7762.editunloadedproject_thumb_37E41DB0.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/7762.editunloadedproject_5F00_thumb_5F00_37E41DB0.png" width="319" height="135" /></a> </p>

<p>Do a search for “_BuildFile” and append the following text within that section of the file:</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">_BuildFile </span><span style="color: red">Include</span><span style="color: blue">=</span>&quot;<span style="color: blue">ServerGenerated\Login.aspx</span>&quot;<span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">SubFolder</span><span style="color: blue">&gt;
  &lt;/</span><span style="color: #a31515">SubFolder</span><span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">PublishType</span><span style="color: blue">&gt;
  &lt;/</span><span style="color: #a31515">PublishType</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">_BuildFile</span><span style="color: blue">&gt;<br /></span><span style="color: blue">&lt;</span><span style="color: #a31515">_BuildFile </span><span style="color: red">Include</span><span style="color: blue">=</span>&quot;<span style="color: blue">ServerGenerated\</span><span style="color: blue">Home.aspx</span>&quot;<span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">SubFolder</span><span style="color: blue">&gt;
  &lt;/</span><span style="color: #a31515">SubFolder</span><span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">PublishType</span><span style="color: blue">&gt;
  &lt;/</span><span style="color: #a31515">PublishType</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">_BuildFile</span><span style="color: blue">&gt;</span></pre>
<a href="http://11011.net/software/vspaste"></a>

<p>Reload the LightSwitch project:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5102.reloadproject_103DA186.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/5102.reloadproject_5F00_103DA186.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="reload-project" border="0" alt="reload-project" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/4048.reloadproject_thumb_04A7E447.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-32-83-metablogapi/4048.reloadproject_5F00_thumb_5F00_04A7E447.png" width="315" height="130" /></a> </p>

<p>Your LightSwitch app is now configured to use your new custom Login page.&#160; When you publish your app and connect to it, you’ll be redirected to your login page.&#160; After successfully logging in, you’ll be redirected to the LightSwitch app.</p>]]></content:encoded>
    </item>
    <item>
      <title>LightSwitch Star Contest</title>
      <link>https://docs.microsoft.com/archive/blogs/mthalman/lightswitch-star-contest</link>
      <pubDate>Mon, 31 Oct 2011 10:54:48 GMT</pubDate>
      <dc:creator><![CDATA[Matt Thalman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mthalman/2011/10/31/lightswitch-star-contest/</guid>
      <description><![CDATA[Think you’ve got what it takes to be a LightSwitch star?&#160; Check out the new LightSwitch...]]></description>
      <content:encoded><![CDATA[<p>Think you’ve got what it takes to be a LightSwitch star?&#160; Check out the new LightSwitch application contest at <a title="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx" href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx">http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>Visual Studio LightSwitch V1 is Released</title>
      <link>https://docs.microsoft.com/archive/blogs/mthalman/visual-studio-lightswitch-v1-is-released</link>
      <pubDate>Tue, 26 Jul 2011 10:00:00 GMT</pubDate>
      <dc:creator><![CDATA[Matt Thalman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mthalman/2011/07/26/visual-studio-lightswitch-v1-is-released/</guid>
      <description><![CDATA[Today is an exciting day.&nbsp; After years of hard work, Visual Studio LightSwitch V1 has been...]]></description>
      <content:encoded><![CDATA[<p>Today is an exciting day.&nbsp; After years of hard work, Visual Studio LightSwitch V1 has been released.&nbsp; This is my first shipped product while working in the Server &amp; Tools Division at Microsoft and I couldn&rsquo;t be happier (my previous shipped products were in the Business Division).&nbsp; Feedback from the first two beta versions has been very positive and we are all excited to have reached this milestone.&nbsp; There seems to be a lot of buzz in the community.</p>
<p>We can all admit that LightSwitch V1 is not a perfect product.&nbsp; It has its quirks and is missing some features that people would like to see.&nbsp; It is a V1 after all.&nbsp; But even so, it&rsquo;s amazing what this product can do for your app building productivity.&nbsp; When I sit down to write an app, I no longer have to ask myself these questions: how am I going to read and write data from the database, how am I going to handle communication between the client and server, how am I going to make the UI functional and look good, how am I going to write the plumbing for authentication.&nbsp; LightSwitch answers these questions for me so I don&rsquo;t have to worry about them.&nbsp; I can concentrate on making the app, not the guts.</p>
<p>As productive as LightSwitch V1 lets you become today, there&rsquo;s still more it can do.&nbsp; This isn&rsquo;t the last version of LightSwitch you&rsquo;re going to see.&nbsp; Stay tuned for more LightSwitch awesomeness in the future.</p>
<p>Happy <span style="text-decoration: line-through;">coding</span> LightSwitching,</p>
<p>Matt</p>]]></content:encoded>
    </item>
    <item>
      <title>Invoking Tier-Specific Logic from Common Code in LightSwitch</title>
      <link>https://docs.microsoft.com/archive/blogs/mthalman/invoking-tier-specific-logic-from-common-code-in-lightswitch</link>
      <pubDate>Tue, 12 Apr 2011 12:41:33 GMT</pubDate>
      <dc:creator><![CDATA[Matt Thalman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mthalman/2011/04/12/invoking-tier-specific-logic-from-common-code-in-lightswitch/</guid>
      <description><![CDATA[Visual Studio LightSwitch makes use of .NET portable assemblies to allow developers to write...]]></description>
      <content:encoded><![CDATA[<p>Visual Studio LightSwitch makes use of <a href="http://msdn.microsoft.com/en-us/library/gg597391.aspx">.NET portable assemblies</a> to allow developers to write business logic that can be executed on both the client (Silverlight) and server (.NET 4) tiers.&#160; In LightSwitch terminology, we refer to the assembly that contains this shared logic as the Common assembly.&#160; In this post, I’m going to describe a coding pattern that allows you to invoke code from the Common assembly that has different implementations depending on which tier the code is running on.</p>  <p>In my scenario, I have a Product entity which has an Image property and the image must be a specific dimension (200 x 200 pixels).&#160; I would like to write validation code for the Image property to ensure that the image is indeed 200 x 200.&#160; But since the validation code for the Image property is contained within the Common assembly, I do not have access to the image processing APIs that allow me to determine the image dimensions.</p>  <p>This problem can be solved by creating two tier-specific implementations of the image processing logic and store that in classes which derive from a common base class that is defined in the Common assembly.&#160; During the initialization of the client and server applications, an instance of the tier-specific class is created and set as a static member available from the Common assembly.&#160; The validation code in the Common assembly can now reference that base class to invoke the logic.&#160; I realize that may sound confusing so let’s take a look at how I would actually implement this.</p>  <p>This is the definition of my Product entity:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/2465.1_118DE500.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/2465.1_5F00_118DE500.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="1" border="0" alt="1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/4213.1_thumb_2E9693C8.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/4213.1_5F00_thumb_5F00_2E9693C8.png" width="447" height="129" /></a></p>  <p>I now need to add some of my own class files to the LightSwitch project.&#160; To do that, I switch the project to File View.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/3036.2_1E8A55C2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/3036.2_5F00_1E8A55C2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="2" border="0" alt="2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/7840.2_thumb_59DDBB80.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/7840.2_5F00_thumb_5F00_59DDBB80.png" width="282" height="195" /></a></p>  <p>From the File View, I add a CodeBroker class to the Common project.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/2477.3_2303673A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/2477.3_5F00_2303673A.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="3" border="0" alt="3" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/5706.3_thumb_104E6D83.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/5706.3_5F00_thumb_5F00_104E6D83.png" width="278" height="261" /></a></p>  <p>The CodeBroker class is intended to be the API to tier-specific logic.&#160; Any code in the Common assembly that needs to execute logic which varies depending on which tier it is running in can use the CodeBroker class. Here is the implementation of CodeBroker:</p>  <p><em>C#:</em></p>  <pre class="code"><span style="color: blue">public abstract class </span><span style="color: #2b91af">CodeBroker
</span>{
    <span style="color: blue">private static </span><span style="color: #2b91af">CodeBroker </span>current;

    <span style="color: blue">public static </span><span style="color: #2b91af">CodeBroker </span>Current
    {
        <span style="color: blue">get </span>{ <span style="color: blue">return </span><span style="color: #2b91af">CodeBroker</span>.current; }
        <span style="color: blue">set </span>{ <span style="color: #2b91af">CodeBroker</span>.current = <span style="color: blue">value</span>; }
    }

    <span style="color: blue">public abstract void </span>GetPixelWidthAndHeight(<span style="color: blue">byte</span>[] image, <span style="color: blue">out int </span>width,<br />                                                <span style="color: blue">out int </span>height);
}</pre>

<p><em>VB:</em></p>

<pre class="code"><span style="color: blue">Public MustInherit Class </span><span style="color: #2b91af">CodeBroker
    </span><span style="color: blue">Private Shared </span>m_current <span style="color: blue">As </span><span style="color: #2b91af">CodeBroker

    </span><span style="color: blue">Public Shared Property </span>Current() <span style="color: blue">As </span><span style="color: #2b91af">CodeBroker
        </span><span style="color: blue">Get
            Return </span><span style="color: #2b91af">CodeBroker</span>.m_current
        <span style="color: blue">End Get
        Set</span>(value <span style="color: blue">As </span><span style="color: #2b91af">CodeBroker</span>)
            <span style="color: #2b91af">CodeBroker</span>.m_current = value
        <span style="color: blue">End Set
    End Property

    Public MustOverride Sub </span>GetPixelWidthAndHeight(image <span style="color: blue">As Byte</span>(),<br />                                                   <span style="color: blue">ByRef </span>width <span style="color: blue">As Integer</span>,<br />                                                   <span style="color: blue">ByRef </span>height <span style="color: blue">As Integer</span>)
<span style="color: blue">End Class
</span></pre>

<p>I next add a ClientCodeBroker class to the Client project in the same way as I added the CodeBroker class to the Common project.&#160; Here’s the implementation of ClientCodeBroker:</p>

<p><em>C#:</em></p>

<pre class="code"><span style="color: blue">using </span>Microsoft.LightSwitch.Threading;

<span style="color: blue">namespace </span>LightSwitchApplication
{
    <span style="color: blue">public class </span><span style="color: #2b91af">ClientCodeBroker </span>: <span style="color: #2b91af">CodeBroker
    </span>{
        <span style="color: blue">public override void </span>GetPixelWidthAndHeight(<span style="color: blue">byte</span>[] image, <span style="color: blue">out int </span>width,<br />                                                    <span style="color: blue">out int </span>height)
        {
            <span style="color: blue">int </span>bitmapWidth = 0;
            <span style="color: blue">int </span>bitmapHeight = 0;

            <span style="color: #2b91af">Dispatchers</span>.Main.Invoke(() =&gt;
            {
                <span style="color: blue">var </span>bitmap = <span style="color: blue">new </span>System.Windows.Media.Imaging.<span style="color: #2b91af">BitmapImage</span>();
                bitmap.SetSource(<span style="color: blue">new </span>System.IO.<span style="color: #2b91af">MemoryStream</span>(image));
                bitmapWidth = bitmap.PixelWidth;
                bitmapHeight = bitmap.PixelHeight;
            });

            width = bitmapWidth;
            height = bitmapHeight;
        }
    }
}</pre>

<p><em>VB:</em></p>

<pre class="code"><span style="color: blue">Imports </span>Microsoft.LightSwitch.Threading

<span style="color: blue">Namespace </span>LightSwitchApplication
<span style="color: blue">    Public Class </span><span style="color: #2b91af">ClientCodeBroker
        </span><span style="color: blue">Inherits </span><span style="color: #2b91af">CodeBroker
        </span><span style="color: blue">Public Overrides Sub </span>GetPixelWidthAndHeight(image <span style="color: blue">As Byte</span>(),<br />                                                    <span style="color: blue">ByRef </span>width <span style="color: blue">As Integer</span>,
                                                    <span style="color: blue">ByRef </span>height <span style="color: blue">As Integer</span>)
            <span style="color: blue">Dim </span>bitmapWidth <span style="color: blue">As Integer </span>= 0
            <span style="color: blue">Dim </span>bitmapHeight <span style="color: blue">As Integer </span>= 0

            <span style="color: #2b91af">Dispatchers</span>.Main.Invoke(
                <span style="color: blue">Sub</span>()
                    <span style="color: blue">Dim </span>bitmap = <span style="color: blue">New </span>Windows.Media.Imaging.<span style="color: #2b91af">BitmapImage</span>()
                    bitmap.SetSource(<span style="color: blue">New </span>System.IO.<span style="color: #2b91af">MemoryStream</span>(image))
                    bitmapWidth = bitmap.PixelWidth
                    bitmapHeight = bitmap.PixelHeight
                <span style="color: blue">End Sub</span>)

            width = bitmapWidth
            height = bitmapHeight
        <span style="color: blue">End Sub
    End Class
End Namespace
</span></pre>

<p>(By default, my application always invokes this <font face="Courier New">GetPixelWidthAndHeight</font> method from the Logic dispatcher.&#160; So the call to invoke the logic on the Main dispatcher is necessary because <font face="Courier New">BitmapImage</font> objects can only be created on the Main dispatcher.)</p>

<p>To include the server-side implementation, I add a ServerCodeBroker class to the Server project.&#160; It’s also necessary to add the following assembly references in the Server project because of dependencies in my image code implementation: PresentationCore, WindowsBase, and System.Xaml.&#160; Here is the implementation of ServerCodeBroker:</p>

<p><em>C#:</em></p>

<pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">ServerCodeBroker </span>: <span style="color: #2b91af">CodeBroker
</span>{
    <span style="color: blue">public override void </span>GetPixelWidthAndHeight(<span style="color: blue">byte</span>[] image, <span style="color: blue">out int </span>width,<br />                                                <span style="color: blue">out int </span>height)
    {
        <span style="color: blue">var </span>bitmap = <span style="color: blue">new </span>System.Windows.Media.Imaging.<span style="color: #2b91af">BitmapImage</span>();
        bitmap.BeginInit();
        bitmap.StreamSource = <span style="color: blue">new </span>System.IO.<span style="color: #2b91af">MemoryStream</span>(image);
        bitmap.EndInit();
        width = bitmap.PixelWidth;
        height = bitmap.PixelHeight;
    }
}</pre>

<p><em>VB:</em></p>

<pre class="code"><span style="color: blue">Public Class </span><span style="color: #2b91af">ServerCodeBroker
    </span><span style="color: blue">Inherits </span><span style="color: #2b91af">CodeBroker
    </span><span style="color: blue">Public Overrides Sub </span>GetPixelWidthAndHeight(image <span style="color: blue">As Byte</span>(),<br />                                                <span style="color: blue">ByRef </span>width <span style="color: blue">As Integer</span>,
                                                <span style="color: blue">ByRef </span>height <span style="color: blue">As Integer</span>)
        <span style="color: blue">Dim </span>bitmap = <span style="color: blue">New </span>System.Windows.Media.Imaging.<span style="color: #2b91af">BitmapImage</span>()
        bitmap.BeginInit()
        bitmap.StreamSource = <span style="color: blue">New </span>System.IO.<span style="color: #2b91af">MemoryStream</span>(image)
        bitmap.EndInit()
        width = bitmap.PixelWidth
        height = bitmap.PixelHeight
    <span style="color: blue">End Sub
End Class
</span></pre>

<p>The next thing is to write the code that instantiates these broker classes.&#160; This is done in the <font face="Courier New">Application_Initialize</font> method for both the client and server Application classes.&#160; For the client Application code, I switch my project back to Logical View and choose “View Application Code (Client)” from the right-click context menu of the project.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/7268.4_24678A0C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/7268.4_5F00_24678A0C.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="4" border="0" alt="4" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/6201.4_thumb_4418F485.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/6201.4_5F00_thumb_5F00_4418F485.png" width="364" height="203" /></a></p>

<p>In the generated code file, I then add the following initialization code:</p>

<p><em>C#:</em></p>

<pre class="code"><span style="color: blue">public partial class </span><span style="color: #2b91af">Application
</span>{
    <span style="color: blue">partial void </span>Application_Initialize()
    {
        <span style="color: #2b91af">CodeBroker</span>.Current = <span style="color: blue">new </span><span style="color: #2b91af">ClientCodeBroker</span>();
    }
}</pre>

<p><em>VB:</em></p>

<pre class="code"><span style="color: blue">Public Class </span><span style="color: #2b91af">Application
    </span><span style="color: blue">Private Sub </span>Application_Initialize()
        <span style="color: #2b91af">CodeBroker</span>.Current = <span style="color: blue">New </span><span style="color: #2b91af">ClientCodeBroker</span>()
    <span style="color: blue">End Sub
End Class</span></pre>

<p>This initializes the CodeBroker instance for the client tier when the client application starts.</p>

<p>I need to do the same thing for the server tier.&#160; There is no context menu item available for editing the server application code but the code file can be added manually.&#160; To do this, I switch my project back to File View and add an Application class to the Server project.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/0312.5_3163FACE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/0312.5_5F00_3163FACE.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="5" border="0" alt="5" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/7367.5_thumb_05B330D2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/7367.5_5F00_thumb_5F00_05B330D2.png" width="265" height="303" /></a></p>

<p>The implementation of this class is very similar to the client application class.&#160; Since the server’s <font face="Courier New">Application_Initialize</font> method is invoked for each client request, I need to check whether the <font face="Courier New">CodeBroker.Current</font> property has already been set from a previous invocation.&#160; Since the <font face="Courier New">CodeBroker.Current</font> property is static, its state remains in memory across multiple client requests.</p>

<p><em>C#:</em></p>

<pre class="code"><span style="color: blue">public partial class </span><span style="color: #2b91af">Application
</span>{
    <span style="color: blue">partial void </span>Application_Initialize()
    {
        <span style="color: blue">if </span>(<span style="color: #2b91af">CodeBroker</span>.Current == <span style="color: blue">null</span>)
        {
            <span style="color: #2b91af">CodeBroker</span>.Current = <span style="color: blue">new </span><span style="color: #2b91af">ServerCodeBroker</span>();
        }
    }
}</pre>
<font color="#0000ff"></font>

<p><em>VB:</em></p>

<pre class="code"><span style="color: blue">Public Class </span><span style="color: #2b91af">Application
    </span><span style="color: blue">Private Sub </span>Application_Initialize()
        <span style="color: blue">If </span><span style="color: #2b91af">CodeBroker</span>.Current <span style="color: blue">Is Nothing Then
            </span><span style="color: #2b91af">CodeBroker</span>.Current = <span style="color: blue">New </span><span style="color: #2b91af">ServerCodeBroker</span>()
        <span style="color: blue">End If
    End Sub
End Class</span></pre>

<p>The next step is to finally add my Image property validation code.&#160; To do this, I switch my project back to Logical View, open my Product entity, select my Image property in the designer, and choose “Image_Validate” from the Write Code drop-down button.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/1401.6_2EBDCFCE.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/1401.6_5F00_2EBDCFCE.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="6" border="0" alt="6" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/32/83/metablogapi/1004.6_thumb_10DF4BCD.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-32-83-metablogapi/1004.6_5F00_thumb_5F00_10DF4BCD.png" width="646" height="196" /></a></p>

<p>In the generated code file, I add this validation code:</p>

<p><em>C#:</em></p>

<pre class="code"><span style="color: blue">public partial class </span><span style="color: #2b91af">Product
</span>{
    <span style="color: blue">partial void </span>Image_Validate(<span style="color: #2b91af">EntityValidationResultsBuilder </span>results)
    {
        <span style="color: blue">if </span>(<span style="color: blue">this</span>.Image == <span style="color: blue">null</span>)
        {
            <span style="color: blue">return</span>;
        }

        <span style="color: blue">int </span>width;
        <span style="color: blue">int </span>height;
        <span style="color: #2b91af">CodeBroker</span>.Current.GetPixelWidthAndHeight(<span style="color: blue">this</span>.Image, <span style="color: blue">out </span>width,<br />                                                  <span style="color: blue">out </span>height);

        <span style="color: blue">if </span>(width != 200 &amp;&amp; height != 200)
        {
            results.AddPropertyError(<br />                <span style="color: #a31515">&quot;Image dimensions must be 200x200.&quot;</span>,<br />                <span style="color: blue">this</span>.Details.Properties.Image);
        }
    }
}</pre>

<p><em>VB:</em></p>

<pre class="code"><span style="color: blue">Public Class </span><span style="color: #2b91af">Product
    </span><span style="color: blue">Private Sub </span>Image_Validate(results <span style="color: blue">As </span><span style="color: #2b91af">EntityValidationResultsBuilder</span>)
        <span style="color: blue">If Me</span>.Image <span style="color: blue">Is Nothing Then
            Return
        End If<br />
</span><span style="color: blue"><br />        Dim </span>width <span style="color: blue">As Integer
        Dim </span>height <span style="color: blue">As Integer
        </span><span style="color: #2b91af">CodeBroker</span>.Current.GetPixelWidthAndHeight(<span style="color: blue">Me</span>.Image, width, height)

        <span style="color: blue">If </span>width &lt;&gt; 200 <span style="color: blue">AndAlso </span>height &lt;&gt; 200 <span style="color: blue">Then
            </span>results.AddPropertyError(<span style="color: #a31515">&quot;Image dimensions must be 200x200.&quot;</span>,<br />                                     <span style="color: blue">Me</span>.Details.Properties.Image)
        <span style="color: blue">End If
    End Sub
End Class</span></pre>

<p>This code can execute on both the client and the server.&#160; When running on the client, CodeBroker.Current will return the ClientCodeBroker instance and provide the client-specific implementation for this logic.&#160; And when running on the server, CodeBroker.Current will return the ServerCodeBroker instance and provide the server-specific implementation.</p>

<p>And there you have it.&#160; This pattern allows you to write code that is invoked from the Common assembly but needs to vary depending on which tier is executing the logic.&#160; I hope this helps you out in your LightSwitch development.</p>]]></content:encoded>
    </item>
    <item>
      <title>Visual Studio LightSwitch Beta 2</title>
      <link>https://docs.microsoft.com/archive/blogs/mthalman/visual-studio-lightswitch-beta-2</link>
      <pubDate>Tue, 15 Mar 2011 12:32:00 GMT</pubDate>
      <dc:creator><![CDATA[Matt Thalman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mthalman/2011/03/15/visual-studio-lightswitch-beta-2/</guid>
      <description><![CDATA[I&rsquo;m very excited to say that we&rsquo;ve released Beta 2 of Visual Studio LightSwitch to MSDN...]]></description>
      <content:encoded><![CDATA[<p>I&rsquo;m very excited to say that we&rsquo;ve released Beta 2 of <a href="http://www.microsoft.com/visualstudio/en-us/lightswitch">Visual Studio LightSwitch</a> to MSDN subscribers.&nbsp; It will be available publicly on Thursday, Mar. 17.&nbsp; So go out there and start downloading.&nbsp; Let us know what you think.</p>]]></content:encoded>
    </item>
  </channel>
</rss>