Azure应用服务错误405-无法完成请求.(不允许的方法) [英] Azure App Service Error 405 - The request could not be completed. (Method Not Allowed)

查看:59
本文介绍了Azure应用服务错误405-无法完成请求.(不允许的方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Xamarin.iOS应用程序的Azure App Service .NET后端.我能够成功注册一个新用户,并且可以在数据库中看到该用户的详细信息.我有一个自定义的ApiController,它可以处理注册,并且我能够通过成功的POST调用保存详细信息.

I'm working with Azure App Service .NET backend with a Xamarin.iOS app. I am able to successfully register a new user and I can see the user's details in the database. I have a custom ApiController, which handles the registration and the I'm able to save the details with a successful POST call.

但是,当我尝试登录该应用程序时,出现以下错误:

However, when I try to log into the app, I get the following error:

{Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The request could not be completed.  (Method Not Allowed) 

下面是我的代码:

后端中的RegistrationController可以成功进行POST调用

[MobileAppController]
[RoutePrefix("api/register")]
[AllowAnonymous]
public class RegisterController : ApiController
{

     [HttpPost]
    [Route("newuser")]
    public HttpResponseMessage NewUser(RegistrationRequest request)
    {
        // Registration code in here

    }

}

这是我在客户端调用此函数的方式:

This is how I call this function on the client side:

public async Task<Result<UserProfile>> RegisterUser(RegistrationWrapper registrationrequest)
    {
        try
        {
            var registrationRequest = new JObject();
            registrationRequest.Add("username", registrationrequest.username);
            registrationRequest.Add("password", registrationrequest.password);
            registrationRequest.Add("email", registrationrequest.email);
            registrationRequest.Add("phone", registrationrequest.phone);
            registrationRequest.Add("firstname", registrationrequest.firstname);
            registrationRequest.Add("lastname", registrationrequest.lastname);

            var result = await client.InvokeApiAsync("register/newuser", registrationRequest);


     // Handle result here

        }
        catch (Exception ex)
        {
            return Result<UserProfile>.Failure(ex.Message + ex.StackTrace + ex.InnerException);
        }

    } 

处理登录的自定义AuthController

此POST调用失败,并出现上述错误.

This POST call fails with the error described above.

 [MobileAppController]
[RoutePrefix("api/auth")]
public class AuthController : ApiController
{
    public HttpResponseMessage Post(AuthenticationRequest credentials)
    {
        try
        {
              //Authentication code goes here

          catch (Exception e)
        {
            Console.WriteLine("Ërror :" + e.Message);
            Console.WriteLine(e.StackTrace);
            return Request.CreateResponse(HttpStatusCode.InternalServerError, new
            {
                Stacktrace = e.StackTrace,
                ErrorMessage = e.Message,
                Credentials = credentials
            });
        }


    }

我如何从客户端调用此功能

How I invoke this function from the client side

 async Task<Result<Account>> Login(string username, string password)
    {
        try
        {
            var credentials = new JObject();
            credentials.Add("username", username);
            credentials.Add("password", password);
            var result = await client.InvokeApiAsync("auth", credentials);


          //Handle result here

        }
        catch (Exception ex)
        {
            return Result<Account>.Failure(ex, ex.Message + ex.StackTrace);
        }

    }

}

我不确定为什么登录期间会失败.有什么想法吗?

I'm not sure why it's failing during the log in. Any ideas?

推荐答案

尝试了StackOverflow上的大量解决方案后,最终为我工作的是在类似的

After trying tons of solutions found here on StackOverflow, the one that finally worked for me was this first answer found on a similar question.

似乎 http POST呼叫已重定向到 https .

It seems that the http POST call is redirected to https.

在Azure门户中的App Service上启用身份验证后,需要将URL更改为https.

After enabling authentication on your App Service in the Azure portal, you need to change the url to https.

所以我从这里改变了我的:

So I changed mine from this:

http//{my_site}.azurewebsites.net

对此:

https//{my_site}.azurewebsites.net

在客户端,现在使用这一新表来创建我的本地同步表.现在一切都按预期进行.

On the client side, and now used this new one to create my local sync tables. Everything works as expected now.

这篇关于Azure应用服务错误405-无法完成请求.(不允许的方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆