title: Using ASP.NET Identity with VB
body: <p>I have researched Google and this site extensively, and cannot find an answer. I'm trying to add ASP.NET Identity to Visual Studio, and I've been working off of <a href="http://www.asp.net/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project" rel="nofollow" title="ASP.NET - Adding Identity to a Web Forms Project">this page</a>.</p>
  
  <p>The problem is, everything from that article is in C#, and my project is specifically in Visual Basic (ASP.NET Framework 4.5.1, <em>not</em> MVC). Also, I'm too new to web dev to know exactly what to change. I found a C# to VB converter, and it worked for the most part but I'm still missing something since I get errors within VS. I'm not even 100% sure I can get Identity to work in VB instead of C#, though I don't see why not. </p>
  
  <p>I'm trying to keep this as concise as possible, so I'll denote the issues in <strong>bold</strong>.</p>
  
  <p>This is the register.aspx page:</p>
  
  <pre><code>&lt;%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Register.aspx.vb" Inherits="WebFormsIdentity.Register" %&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body style="font-family: Arial, Helvetica, sans-serif; font-size: small"&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;h4 style="font-size: medium"&gt;Register a new user&lt;/h4&gt;
          &lt;hr /&gt;
          &lt;p&gt;
              &lt;asp:Literal runat="server" ID="StatusMessage" /&gt;
          &lt;/p&gt;                
          &lt;div style="margin-bottom:10px"&gt;
              &lt;asp:Label runat="server" AssociatedControlID="UserName"&gt;User name&lt;/asp:Label&gt;
              &lt;div&gt;
                  &lt;asp:TextBox runat="server" ID="UserName" /&gt;                
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div style="margin-bottom:10px"&gt;
              &lt;asp:Label runat="server" AssociatedControlID="Password"&gt;Password&lt;/asp:Label&gt;
              &lt;div&gt;
                  &lt;asp:TextBox runat="server" ID="Password" TextMode="Password" /&gt;                
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div style="margin-bottom:10px"&gt;
              &lt;asp:Label runat="server" AssociatedControlID="ConfirmPassword"&gt;Confirm password&lt;/asp:Label&gt;
              &lt;div&gt;
                  &lt;asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" /&gt;                
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;div&gt;
                  &lt;asp:Button runat="server" OnClick="CreateUser_Click" Text="Register" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>No errors in VB, but upon after running the page I get a 'Parser Error' in the browser: "<strong>Parser Error Message: Could not load type 'WebFormsIdentity.Register</strong>'."</p>
  
  <p>This is the code behind; the majority of the issues are with this page:</p>
  
  <pre><code>Imports Microsoft.AspNet.Identity
  Imports Microsoft.AspNet.Identity.EntityFramework
  Imports System.Linq
  
  Namespace WebFormsIdentity
      Partial Public Class Register
          Inherits System.Web.UI.Page
          Protected Sub CreateUser_Click(sender As Object, e As EventArgs)
              ' Default UserStore constructor uses the default connection string named: DefaultConnection
              Dim userStore = New UserStore(Of IdentityUser)()
              Dim manager = New UserManager(Of IdentityUser)(userStore)
  
              Dim user = New IdentityUser() With { _
                  Key .UserName = UserName.Text _
              }
              Dim result As IdentityResult = manager.Create(user, Password.Text)
  
              If result.Succeeded Then
                  StatusMessage.Text = String.Format("User {0} was created successfully!", user.UserName)
              Else
                  StatusMessage.Text = result.Errors.FirstOrDefault()
              End If
          End Sub
      End Class
  End Namespace
  </code></pre>
  
  <p><strong>On the line under 'Dim user', the word 'Key' has this error:</strong> </p>
  
  <blockquote>
    <p>Name of field or property being initialized in an object initializer must start with '.'.</p>
  </blockquote>
  
  <p><strong>On the line with 'Dim result', the word 'Password' has this:</strong></p>
  
  <blockquote>
    <p>'Password' is not declared. It may be inaccessible due to its protection level</p>
  </blockquote>
  
  <p><strong>On the line under 'result.Succeeded', the word 'StatusMessage' has this:</strong></p>
  
  <blockquote>
    <p>'StatusMessage' is not declared. It may be inaccessible due to its protection level.</p>
  </blockquote>
  
  <p><strong>And finally, same line, 'user.UserName' has this:</strong></p>
  
  <blockquote>
    <p>'UserName' is not a member of 'System.Security.Principal.IPrincipal'.</p>
  </blockquote>
  
  <p>I've only been using VB for about six weeks, so I'm a baby dev. I do know how to declare things, but I don't understand why the author of the above link didn't have to do anything extra in his code, except that it is C#. </p>
  
  <p>Anyway, thanks for reading and for the assistance in advance. </p>