asp.net mvc - WebSecurity issue : Initialize database connection -


i got issue while trying put in place authentication system. i'm using asp.net mvc 4 , linq sql classes.

first of all, there login view calls related controller. i'm doing connect , redirect users following roles.

public class logincontroller : controller {     //     // get: /login/     t2a_dataclassesdatacontext db;      public logincontroller()     {         db = new t2a_dataclassesdatacontext();     }     public actionresult index()     {         return view();     }      [httppost]      public actionresult index(loginviewmodel lvm)     {         if (modelstate.isvalid)         {             if (websecurity.login(lvm.username, lvm.password, false))             {                 var login = u in db.users u.username == lvm.username select new user { username = u.username, password = u.password, isadmin = u.isadmin };                  user user = (user)login;                  string role = user.isadmin == true ? "utilisateur" : "administrateur";                  return redirecttoaction("index", role);              }              else             {                 modelstate.addmodelerror("", "identifiants erronés !");             }         }          return view();     }  } 

when compile solution, enter right credentials , submit it, fails , got :

you must call "websecurity.initializedatabaseconnection" method before call other method of "websecurity" class. call should placed in _appstart.cshtml file in root of site.

i know message pretty clear don't know how proceed that. guys?

websecurity. initializedatabaseconnection prime database used membership provider creating necessary tables. have call before calling other feature of websecurity. in application, locate application_start ( in global.ascx.cs) , have initialization code called in it. example

if (!websecurity.initialized)     websecurity.initializedatabaseconnection("yourconnectionstringinconfigfile","userprofile", "userid", "username", autocreatetables: true); 

yourconnectionstringinconfigfile connection string in webconfig. after calling above code, websecurity create table name userprofile along other required tables.

good luck


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -