2017-07-11 11 views
1

を許可されていない私は私のXamarin.Formsアプリケーションで認証を有効にするには、このチュートリアルに従っ: https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter2/custom/Azureのアプリケーションサービス - カスタム認証 - HTTP動詞

テストをポストマンで(チュートリアルで説明したように)正常に行ってきました。トークンが返されました。

私は好きで、私はエラーを得た

LoginAsync("custom", Newtonsoft.Json.Linq.JObject.FromObject(auth)); 

...私のC#のコードからこれを呼び出す:私はAzureのSDKは、POSTを送信し、呼び出すときに、要求をGETことが判明

Method not allowed. HTTP Verb not allowed 

LoginAsync。だから私は変わっこれまでこの...

[HttpPost, Route(".auth/login/custom")] 
     public IHttpActionResult Post([FromBody]CPM.Arda.Mobile.Freelancer.Backend.DataObjects.Recruitment.Custom.PromoterAuthRequest promoterAuth) 

...

[HttpPost, HttpGet, Route(".auth/login/custom")] 
     public IHttpActionResult Post([FromBody]CPM.Arda.Mobile.Freelancer.Backend.DataObjects.Recruitment.Custom.PromoterAuthRequest promoterAuth) 

HTTP動詞のエラーがなくなっていますが、次のエラーが発生します

Operation=ReflectedHttpActionDescriptor.ExecuteAsync, Exception=System.NullReferenceException: Object reference not set to an instance of an object. 
    at CPM.Arda.Mobile.Freelancer.Backend.Controllers.Custom.CustomAuthController.Post(PromoterAuthRequest promoterAuth) 
    at lambda_method(Closure , Object , Object[]) 
    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) 
    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) 
    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext() 
2017-07-11T10:39:50 PID[9680] Error  Operation=ApiControllerActionInvoker.InvokeActionAsync, Exception=System.NullReferenceException: Object reference not set to an instance of an object. 
    at CPM.Arda.Mobile.Freelancer.Backend.Controllers.Custom.CustomAuthController.Post(PromoterAuthRequest promoterAuth) 
    at lambda_method(Closure , Object , Object[]) 
    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) 
    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) 
    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) 

私は本当に困惑しています。このトピックの利用可能なチュートリアルは、すぐに使用できるようには見えません。

+0

。 – juunas

答えて

1

私はAzureのSDK がPOSTを送信し、LoginAsyncを呼び出すときに、要求をGETことが分かりました。

私の知る限りでは、モバイルアプリのバックエンドは、HTTPSを強制する、とあなたはhttpでリクエストを送信する場合、以下のように、あなたは302のステータスコードを取得します:リダイレクト、言及したこのissueとして

enter image description here

http - > httpsからhttp動詞がGETになります。

MobileServiceClientを初期化するときにモバイルアプリUriをHttpsに変更すると、コードが期待通りに機能します。お使いのコントローラのアクションで発生するとNullReferenceExceptionのように見えます

enter image description here

+0

パーフェクト。それはあなたに感謝します – OPunktSchmidt

関連する問題