matt11

Web pages - WebSecurity database

5 posts in this topic

Following ASP.NET tutorial, i have a problem (can't figure out how to) with creating account/logging into a database.

 

database: http://postimg.org/image/6k4ew5kkp/

 

_AppStart.cshtml:

@{

WebSecurity.InitializeDatabaseConnection("SmallBakery", "Product", "Id", "Name", true);

}

 

i have added :

<appSettings>

<add key="enableSimpleMembership" value="true" />

</appSettings>

into Web.config

 

Default.cshtml:

@{

bool value=WebSecurity.Login("Bread", "parabola", true);

}

<html>

<body>

<p>It is @value</p>

</body>

</html>

 

returns: It is False

 

also some other tables are created i dont know why ?: http://postimg.org/image/g3e3pm82x/

 

i think it's something password related, bcz UserExists() and GetUserId() work.

Share this post


Link to post
Share on other sites

The username and password need to be set up as a database user and password. It looks like you're trying to store the usernames and password in the database. When you connect to the database you give it a username and password set up on the database server which has permission to access the database.

Share this post


Link to post
Share on other sites

ok, now ...

 

Users database is created and has UserProfile and some other empty tables.

 

_AppStart.cshtml:

@{

WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", true);

}

 

Default.cshtml:

@{

WebSecurity.CreateAccount("tom2", "23456", false);

}

<html>

<body>

<p>It is value</p>

</body>

</html>

 

i get an error on line: WebSecurity.CreateAccount("tom2", "23456", false);

Description: An unhandled exception occurred during the execution of the current web request.

Exception Details: System.Web.Security.MembershipCreateUserException: The Provider encountered an unknown error.

Share this post


Link to post
Share on other sites

This page shows a few conditions why it might throw that exception:https://msdn.microsoft.com/en-us/library/webmatrix.webdata.websecurity.createaccount(v=vs.111).aspx?cs-save-lang=1&cs-lang=csharpI'm not quite sure what "the database operation failed" would mean, that's not a lot of information to go on.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now