When you create a project in asp.net from visual studio, and choose the web application option, it generates some files that allow you to place some headings that are the following:
[Authorize]
[InitializeSimpleMembership]
These allow me to validate if the user is logged in to allow access to the views.
My question is how can I do this myself, but when I create an empty / white project? I have seen some examples as described in the following link:
but it turns out that in my case it does not work, and most likely because the example is for SQLSERVER, and I'm using MySql.
When trying to prove as shown by the link example, I get the following error:
Unable to open the database "db_user" requested by the login. Login failed
this error gives in the login view that it is like this:
public ActionResult Login()
{
if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection("MembershipDbContext", "usuarios", "password", "email", autoCreateTables: true);
}
return View();
}
and in the webconfig it looks like this:
<add name="MembershipDbContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=usuario_bd;Integrated Security=True" providerName="System.Data.SqlClient" />
but when I try to try it this way in the webconfig:
<add name="MembershipDbContext" connectionString="SERVER=150.011.252.252;Initial Catalog=secure_login;Integrated Security=True" providerName="MySql.Data.MySqlClient" />
I get the following error:
Authentication to host '150.011.252.252' for user 'auth_windows' using method 'authentication_windows_client' failed with message: Access denied for user 'auth_windows'@'186-106-11-194.baf.movistar.cl' (using password: NO)
I would like to know what the solution to this would be. In any case, the objective is to be able to restrict users, not allowing access to views or pages if you are not logged in. Ideally, it would be to have roles, but it would be a separate issue.