###前提
Visual studio 2013 for webで開発をしております。
VB/C#いずれでもかまいません(実際にはVBで開発しています)。
新しくMVC5アプリケーションをテンプレートから生成したあと、
以下の拡張を行いました:
/models/ientityModel.vb
....(imports省略).... ' ApplicationUser クラスにプロパティを追加することでユーザーのプロファイル データを追加できます。詳細については、http://go.microsoft.com/fwlink/?LinkID=317594 を参照してください。 Public Class ApplicationUser Inherits IdentityUser ''' <summary> ''' 登録連番 ''' </summary> <Required> <Display(Name:="登録連番")> <DatabaseGenerated(DatabaseGeneratedOption.Identity)> <Column("ID_NUM", Order:=0)> Public Property Id_Num As Integer Public Async Function GenerateUserIdentityAsync(manager As UserManager(Of ApplicationUser)) As Task(Of ClaimsIdentity) ....
こうすると、ApplicationUserManager(UserManager)において、登録連番が定義されると思います。
また、標準では ほかに、 PhoneNumber属性も持っています。
###実現したいこと
1)アカウントを生成した後、dbを調整して、以下とします:
- PhoneNumber属性に適当なstringが入っている(例として:"0120-000-000")
- Id_Num属性に、登録連番(DBから振られる連番) が入っている
2)1の状態で、生成したアカウントにサインインします。
3)ページには電話番号と連番が表示されるようにしたいです。
###ソース、試したこと
以下のソースを書きましたが、IDE画面のオートコンプリートに、メソッドが出てきません。
また、クラス継承がうまくいっていないのか、
'getPhoneNumber' は 'System.Security.Principal.IIdentity' のメンバーではありません。 'getIdNum' は 'System.Security.Principal.IIdentity' のメンバーではありません。
というエラーがでて表示がうまくできません
VB.net / modules/test.vb
Module Extensions <System.Runtime.CompilerServices.Extension> Public Function GetIdNum(This As System.Security.Principal.IIdentity) As Integer? Dim userIdentity = TryCast(This, ApplicationUser) If userIdentity IsNot Nothing Then Return userIdentity.Id_Num() Else Return Nothing End If End Function <System.Runtime.CompilerServices.Extension> Public Function GetPhoneNumber(This As System.Security.Principal.IIdentity) As String Dim userIdentity = TryCast(This, ApplicationUser) If userIdentity IsNot Nothing Then Return userIdentity.PhoneNumber() Else Return Nothing End If End Function End Module
/views/index.vbhtml
@Imports Microsoft.AspNet.Identity @Imports System.Security.Principal @ModelType ApplicationUser @Code End Code ... ログインしているとあなたのIDと電話番号が表示されます [ @User.Identity.getId_Num : @User.Identity.getPhoneNumber ] ...
###具体的なゴール
@User.Identity.getPhoneNumber @User.Identity.GetIdNum を、
ログインしていればビューから呼び出せればOkです。
なお現時点で、以下は表示できています:
- @User.Identity.GetUserName
- @User.Identity.GetUserId
- @User.Identity.Name
- @HttpContext.Current.User.Identity.GetUserName
###補足情報(言語/FW/ツール等のバージョンなど)
VisualStudio 2013 VB / C# , SQLserver 2014
上記、どうぞよろしくお願い申し上げます。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/07 04:46
退会済みユーザー
2017/04/07 06:04
2017/04/07 06:36
退会済みユーザー
2017/04/07 08:15 編集