Click here to Skip to main content
15,891,993 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi everyone,

i am creating a portal in which three roles are there for user like 1 is for teachers, 1 is for students, and the other is for users(normal). i am using html5,jquery,javascript for interface, backbone.js and web api.i wanted to create login service for all users in that when user register data will be saved in sql database and also want to create new token and when user login he should get the token in return dat will be used for every request in that portal which has users information like userid and other info which will be used in some request. this service want to create in web api and use it with backbone.js.

so am i on right track can this be possible. if yes than how?? i am badly needed your help..

kindly please ignore my poor language..


Thanks in Advance..
Posted

did you want to know the technology ? basically for client side, backbone.js is very beautiful. if you want to use web api then it depends on your requirement.

Now for authentication process, if you use forms authentication then you can create a ticket to set it to cookie.Also you can store the user identification( GenericIdentity ) to HttpContext.Current.User also to get the logged in user's information from any where of the application.
 
Share this answer
 
Comments
ADonda 8-Dec-13 4:15am    
thank you very much for the information.. can u please give me the demo link if u know so that i know the basic working of that and easily will get to know..
C#
public static void SetAuthInfo(Guid Id, string Email, string FullName, string Role, Guid PersonId, Guid OrganizationId
            , string exchangeUID, string exchangePWD, string exchangeDomain,int? fileManagerPermission)
        {
            if (HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName] != null)
            {
                HttpContext.Current.Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
                
            }

            string fullName = FullName;

            var ticket = new FormsAuthenticationTicket(
                1,
                fullName,
                DateTime.Now,
                DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes),
                false,
                string.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}", Email, Id, FullName, Role, PersonId, OrganizationId, exchangeUID,
                July.Common.Encryption.Encrypt(exchangePWD), exchangeDomain, fileManagerPermission==null?0:fileManagerPermission));

            var encryptedTicket = FormsAuthentication.Encrypt(ticket);
            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
            {
                HttpOnly = true,
                Secure = FormsAuthentication.RequireSSL
            };
            var ASPSESSID = new HttpCookie("ASPSESSID")
            {
                HttpOnly = true,
                Secure = FormsAuthentication.RequireSSL,
                Expires = DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes)
            };


            var identity = new GenericIdentity(ticket.Name);
            var principal = new CustomUserPrincipal(identity, Id, Email, Role, FullName, PersonId, OrganizationId, exchangeUID, exchangePWD, exchangeDomain);
            HttpContext.Current.User = principal;
}


The above code will be used to set the authentication info after login. In web.config file, you need to add the following nodes.

XML
<authentication mode="Forms">
    <forms defaultUrl="~/Home/Index" timeout="30" name="FormsAuthentication" loginUrl="~/Account/Login" />
  </authentication>
  <authorization>
    <deny users="?" />
  </authorization>


Then create a page for login. validate in and if validate then store the data by above SetAuthInfo.
 
Share this answer
 
Comments
ADonda 16-Dec-13 2:18am    
hey hi Amir i tried this but didnt come to any results.. please can u explain other ways which i can use for this?
[no name] 17-Dec-13 3:14am    
if you have enough time, then please let me know how you went to implement forms authentication step by step.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900