私は許可属性を追加する前に動作していたWeb APIプロジェクトで既存のデータレイヤーを使用しようとしていますが、テーブルはコンテキストの一部ではないというこれは、ユーザー名とパスワードストアが、自分のエンティティが属するSQL Serverではなく、ローカルのSQLデータベースを使用するためです。テーブルは現在のコンテキストにありません。web api issue
今私はユーザーからのトークンをローカルデータベースに置くレジスタ関数の下に置いています。だから、私はapiをテストするためにpost manのAuthorizationヘッダーに置いておいた次のものを私に返しました。
GET/API /はcustomerinfo/B737069E-A835-40EC-BDF7-0CA4821C4D59 HTTP/1.1 ホスト:localhostを:54010 のContent-Type:アプリケーション/ JSON許可: ベアラs159EgZ1KwRvq53eEWeAYTupJlpUGLaDWXTy4Z39ezUX3Ac41HA7v6l3F2uFfW8eJde8eSS-kWKTn05IIkHnIKS-U2IdoaRssS8hZhCAqe9REL8SWFqo92i9kZrbnSMIhC1V73Lt0kMYf_mnjSSFM33OGVe7JHR4-5NUezvO --eI9XtFx6OH5ZCYYmBZo2UhIxt3Ma7jDaFv22c5lx7wrCfL1d2xXgrWTGtWL7QM6mZ18nxncsOT49XFpcEQhAv0a1DRf9ygVZUVYq-L0JSlz_PnZy6YUPuzlzmL0lgcjhTXKYK4f7chI3cIG9Tl96nfn9VxFMQm8XDgxHBWHNFsHp7z3JG9FwGIAtirfiizt-SAmlcXGxxZ0BONHGS18wlMjq_1DkmtGEoz9LQoqn6AdmydGO2fXH2Of-jNR_VCktGvE9D5Uj9PmysU7FNtNtUcoIlYgoTlgPlUnl9k443C1uBU3ZoZCh10Z2wRDoceGMtjFycOW99N00l4fOXGhjmn キャッシュ-control:キャッシュなしポストマン・トークン: 1fbb870c-af27-A effを-7d36-7520b530c6b8
これは私がセットアップバーラートークン
public class CustomerInfoController : ApiController
{
private portalEntities db = new portalEntities();
// GET: api/CustomerInfo
public IQueryable<tblPortalCustomerInfo> GettblPortalCustomerInfoes()
{
return db.tblPortalCustomerInfoes;
}
// GET: api/CustomerInfo/5
[Authorize]
public async Task<IHttpActionResult> GettblPortalCustomerInfo(Guid id)
{
tblPortalCustomerInfo tblPortalCustomerInfo = await db.tblPortalCustomerInfoes.FindAsync(id);
if (tblPortalCustomerInfo == null)
{
return NotFound();
}
return Ok(tblPortalCustomerInfo);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
[Authorize]
private bool tblPortalCustomerInfoExists(Guid id)
{
return db.tblPortalCustomerInfoes.Count(e => e.id == id) > 0;
}
}
を持っているか。これは私が呼び出しています顧客情報クラスですポストマンで
public class CustomerInfoController : ApiController
{
private portalEntities db = new portalEntities();
// GET: api/CustomerInfo
public IQueryable<tblPortalCustomerInfo> GettblPortalCustomerInfoes()
{
return db.tblPortalCustomerInfoes;
}
// GET: api/CustomerInfo/5
[Authorize]
public async Task<IHttpActionResult> GettblPortalCustomerInfo(Guid id)
{
tblPortalCustomerInfo tblPortalCustomerInfo = await db.tblPortalCustomerInfoes.FindAsync(id);
if (tblPortalCustomerInfo == null)
{
return NotFound();
}
return Ok(tblPortalCustomerInfo);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
[Authorize]
private bool tblPortalCustomerInfoExists(Guid id)
{
return db.tblPortalCustomerInfoes.Count(e => e.id == id) > 0;
}
}
エラーが https://snag.gy/kQYIUP.jpg
012です"ExceptionMessage": "tblPortalCustomerInfoは、現在のコンテキストのモデルの 一部ではないエンティティタイプ"、 "ExceptionType": "のSystem.InvalidOperationException"、 "のStackTrace": " System.Data.Entity.Internalで.InternalContext.UpdateEntitySetMappingsForType(タイプ entityType)\ R \ nは System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(タイプ entityType)で\ R \ nは でSystem.Data.Entity.Internal.Linq.InternalSet
1.Initialize()\r\n at System.Data.Entity.Internal.Linq.InternalSet
1 .get_InternalContext()\ r \ n at System.Data.Entity.Internal.Linq.InternalSet1.FindAsync(CancellationToken cancellationToken, Object[] keyValues)\r\n at System.Data.Entity.DbSet
1.FindAsync(CancellationToken cancellationToken、Object [] kSystem.Data.Entity.DbSet1.FindAsync(Object[] keyValues)\r\n at portalWebApi.Controllers.CustomerInfoController.<GettblPortalCustomerInfo>d__2.MoveNext() in C:\\Projects\\Client-Portal\\portalWebApi\\Controllers\\CustomerInfoController.cs:line 35\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3
1.MoveNext()\ r \ n --- 例外がスローされた前の場所からのスタックトレースの末尾 ---システムで\ r \ n .Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(タスク タスク)\ R \ n System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotificationで(タスク タスク)\ R \ n でSystem.Web.Http.Controllers.ApiControllerActionInvoker.d__0 .MoveNext()\ r \ n --- 例外がスローされた前の場所からのスタックトレースの末尾 --- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(タスク タスク)で\ r \ n \ r \ n at System.Runtime.CompilerServices.TaskAwaiter.HandleN onSuccessAndDebuggerNotification(タスク タスク)\ r \ n( )System.Web.Http.Controllers.ActionFilterResult.d__2。MoveNext()\ r \ n --- 例外がスローされた前の場所からのスタックトレースの終了 --- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(タスク タスク)で\ r \ n System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(タスク タスク)\ rを\ nは System.Web.Http.Filters.AuthorizationFilterAttribute.d__2.MoveNext()で\ R \ nは--- 以前からスタックトレースの終わり例外がSystem.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(タスク タスク)で --- \ Rの\ nを投げた場所\ R \ nは System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotificationで(タスク タスク)\ R \ n System.Web.Http.Filters.AuthorizationFilterAttribute.d__2.MoveNext()\ r \ n --- System.Runtime.CompilerServicesで例外がスローされた前の場所からのスタックトレースの末尾が --- \ r \ nです。 TaskAwaiter.ThrowForNonSuccess(タスク タスク)\ R \ nは System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(タスク タスク)で\ R \ nは System.Web.Http.Controllers.AuthenticationFilterResult.d__0.MoveNext(AT)\ r \ n --- 例外がスローされた前の場所からのスタックトレースの末尾 --- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(タスク タスク)で\ r \ n にSystem.Runtime .CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(タスク)タスク)\ rを\ nは でSystem.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()」
asp.netアイデンティティを使用していますか?バックエンドテーブルとセキュリティテーブルの両方に別々のコンテキストを使用しますか? –
@HaithamShaddad web api 2テンプレートを使用してIDと私のコンテキストにsepのコンテキストが私は理解できないなぜ私は許可タグを使用して私のテーブルを見つけることができません –