简体   繁体   中英

Cannot generate a consistant token ASP.NET C# server-side Oauth2.0

I am having troubles trying to autogenerate a token that all client-side users can use. Am using Oauth 2.0.

I can perfectly generate a token localhost, using Account controller /api/Account/Register , but when I publish the web api I cannot access with that token, and I also can't generate the token like I did localhost.

Is there any way to generate a token server-side like I do localhost?, it should be consistent in the way that when I republish the app that token should still be the same.

I am using Postman to test it. When I call /api/Account/Register with this json:

{
  "Email": "da@a.com",
  "Password": "sample striAng 21|",
  "ConfirmPassword": "sample striAng 21|"
}

it returns me an error in like this:

{
    "Message": "An error has occurred."
}

I am copying exactly what I did localhost, but on server doesn't work.

it looks like 500 internal server error. Any other endpoint is working all everything dosn't work?

You shold check connection string on server, and check if db exist and have proper tables.

Make sure that any envirement specyfic setting has valid value.

The problem is that you're connecting to a SQL Express Database on your local machine, but in most of the cases Servers don't use SQL Express (Nor have the same credentials when login to it) you MUST set up your web.config and sql connection.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)"

On your Web.config change/comment out your current connectionStrings and replace it with the one of your server

 <connectionStrings>       
    <add name="YourDataBaseContextName" connectionString="Data Source=TheConnection;Initial Catalog=YourDataBaseName;User Id=TheUserOfDatabase;Password=YourHopeNotSoEasyPassword;" providerName="System.Data.SqlClient" />
 </connectionStrings>

What i don't understand here is why I have a sql problem, being that Account controller never uses any database?

They do use it, after all you must save the register data on somewhere, right?

More specifically this lines register and save to database the model that you send:

var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };    
IdentityResult result = await UserManager.CreateAsync(user, model.Password);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM