hello i have some integration problem with my sql server and visual studio, so whenever i try to set user roles from web admin tools it shows the error "unable to connect to sql server/unable to set roleprovider etc etc". so im thinking of configuring the web.config files manually.but not sure how to do it.ive seen some ways of authenticating the users but the codes are written separately and i dont know how to assemble them into one piece.here are my codes,please provide me some guidance/links
1.2.Code:<authentication mode="Forms"> <forms defaultUrl="Default.aspx" loginUrl="~/Login.aspx" slidingExpiration="true" timeout="20"></forms> </authentication>3.Code:<location path="Admin"> <system.web> <authorization> <allow roles="admin"/> <deny users="*"/> </authorization> </system.web> </location>4.Code:<system.web> <authorization> <allow roles="user"/> <deny users="*"/> <deny users="?"/> </authorization> </system.web>Code:protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { string userName = Login1.UserName; string password = Login1.Password; bool rememberUserName = Login1.RememberMeSet; //Fetch User login information fromthe xml file into Dataset string xmlFilePath = Server.MapPath("~/App_Data/LoginInfo.xml"); DataSet objDs = new DataSet(); objDs.ReadXml(xmlFilePath); DataRow[] dRow = objDs.Tables[0].Select("UserName = '" + userName + "' and Password = '" + password + "'"); if (dRow.Length > 0) { //Fetch the role string roles = dRow[0]["Roles"].ToString(); //Create Form Authentication ticket FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(20), rememberUserName, roles, FormsAuthentication.FormsCookiePath); // In the above parameters 1 is ticket version, username is the username associated with this ticket //time when ticket was issued , time when ticket will expire, remember username is user has chekced it //roles associted with the user, and path of cookie if any //For security reasons we may hash the cookies string hashCookies = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies); // add the cookie to user browser Response.Cookies.Add(cookie); // get the requested page string returnUrl = Request.QueryString["ReturnUrl"]; if (returnUrl == null) returnUrl = "~/Default.aspx"; Response.Redirect(returnUrl); }


Reply With Quote
