Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my sql db I have permissions to allow users access to different web pages in my app. I have a page where i can dynamically change the permissions of the users during runtime. Can I allow/deny user access without using web.config?
Here's my code so far in a class:
C#
public static int AllowUserAccess(int agentID, string formName)
        {
            SqlDataReader reader;
            int userid = 0;
            try
            {
                conn = OpenConnection();
                comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandType = CommandType.Text;
                comm.CommandText = "Select a.pkAgentID, PERM.FormName, AGP.fkAgentGroupID, agp.AllowAccess from Agents A inner join AgentGroupPermissions AGP on a.fkAgentGroupID = agp.fkAgentGroupID inner join Permission Perm ON AGP.fkPermissionID = PERM.pkPermissionID WHERE A.pkAgentID = @AgentID AND PERM.FormName = @FormName";
                comm.Parameters.Add("@AgentID", SqlDbType.Int).Value = agentID;
                comm.Parameters.Add("@FormName", SqlDbType.VarChar).Value = formName;


                reader = comm.ExecuteReader();

                if (reader.IsClosed == false)
                {
                    reader.Close();
                }

                return userid;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                return userid;
            }
        }


In my site.master i wish to get this function and use it to authorize certain permissions once the user logs in. This is what I have so far:
C#
protected void AllowAccess()
       {
           SqlCommand comm = new SqlCommand();
           string id = Request.Params["AgentID"];
           int agentID = Convert.ToInt32(id);
           string form = "";

           int access = DataFunctions.AllowUserAccess(agentID, form);
           bool allow = false;

           if (allow == true)
           {

           }
           else
           {
               Response.Redirect("Login.aspx");
           }
       }

I'm stuck and I do not know what else to do in regards of getting the AllowAccess value and then getting a path or to show the specific web pages for each particular user.
Posted
Updated 26-Nov-12 1:20am
v2
Comments
ZurdoDev 26-Nov-12 8:49am    
What's the issue? It looks like you have code to validate whether or not they can access a page. What's wrong?

1 solution

change your permissions with Ajax ; first make a page that can change permissions when you send a quarry string then send id in client side to that page ...
hope help full
 
Share this answer
 

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