Posted on: 3/16/2011 10:33:06 AM | Views : 235

Hi,
I have a webapp that contains many webpages. Different users will have a different login to the webapp, hence different user roles assignment to webpages. Looking at ASP.NET's SqlRoleProvider implementation, I feel that I need to create a lot of roles to cater for the many different roles combination.
In classic ASP, I would call a function (user_role("role_name")) in every webpage to validate if user is authorize. Below is the codes for the function:
function user_role(sLevel) if session("user_name") = "" then response.redirect("../login.asp?ret_page=" & to_url(request.serverVariables("SCRIPT_NAME")&"?"&request.serverVariables("QUERY_STRING"))) else 'Retrieve user roles sql = "SELECT role FROM user_roles WHERE user_name = " & to_sql(session("user_name"),"text") & " AND role = " & to_sql(sLevel,"text") set rs = cn.Execute(sql) if rs.EOF then 'No roles assigned response.redirec ...

Go to the complete details ...