Click here to Skip to main content
15,888,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a project that runs a stored procedure to determine the user 's permissions and what they should see.

I tested my site locally, cleaned and built the solution, published it to m desktop, then moved the files over to the test server.

Everything works. I changed my own user permissions, logged back in to the test server but it still shows my previous permissions!

I output the user.identitiy on the page, had another user log in, saw the right user name but still my permissions!

I have used TRIPLE checked and verified my user info is not hardcore do in the stored proc call and it isn't.a

Is there some setting I missed when I built and published my solution that is overriding the user name information??

What I have tried:

I have searched Google, verified my code, searched this knowledge base.
Posted
Updated 12-Aug-16 10:32am

My guess is that the stored procedure code that is checking the permissions has a bug!
You said that you "verified my code", but never stated that you tried and were able to verify that it ever identified anything other than your permissions!

Can you verify that much on your local system?
Then try again with moving to the test server.
If that fails, then I suggest examining the relevant DB tables for your not you user and manually simulating (on paper!) the stored procedure for that user.

It's just going to be good, old fashioned debugging!
 
Share this answer
 
Matt,

I did try and verify that it identified anything other than my permissions.

Below is the code to my Main.aspx page and my Main.aspx.cs page. It is pretty simple logic that runs fine when the Main.aspx page loads on the production server but won't recognize changes on the test server - the permissions seem to default to my own. I checked to be sure I wasn't accidentally passing local Client controls when I published from my desktop to the test server and I wasn't:

C#
Page Name is Main.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Main.aspx.cs" Inherits="MyWebPage.WebForm2"%>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

This is on the Main.aspx.cs page:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using System.Security.Principal;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Configuration;

namespace MyWebPage.Main
{

    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                var username = User.Identity.Name;
                

                SqlConnection MyConnection = new SqlConnection("server=ServerName\\sql2008;database=DatabaseName;Trusted_Connection=True;");

                SqlDataAdapter MyDataAdapter = new SqlDataAdapter("SP_Name", MyConnection);

                MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;

                MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@username", SqlDbType.VarChar, 40));

                MyDataAdapter.SelectCommand.Parameters["@username"].Value = (username);

                MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@userrole", SqlDbType.VarChar, 40));

                MyDataAdapter.SelectCommand.Parameters["@userrole"].Direction = ParameterDirection.Output;

                DataSet DS = new DataSet();

                MyConnection.Open();

                MyDataAdapter.Fill(DS, "UsersRole");

                Session.Add("Role", DS);

                string userrole = null;

                userrole = MyDataAdapter.SelectCommand.Parameters[1].Value.ToString();

                string role1 = "Admin";
                string role2 = "User";
                string role3 = "Managers";
                string role4 = "PowerUser";
             
              

                //TextBox1.Text = MyDataAdapter.SelectCommand.Parameters[1].Value.ToString();

                //Label1.Text = MyDataAdapter.SelectCommand.Parameters[1].Value.ToString();


                if (userrole == role1)
                {
                    Server.Transfer("Main.aspx", true);
                }
                else if (userrole == role2)
                {
                    Server.Transfer("UserMainPage.aspx", true);
                }
                else if (userrole == role3)
                {
                    Server.Transfer("ManagerMainPage.aspx", true);
                }
                else if (userrole == role4)
                {
                    Server.Transfer("PowerUserMainPage.aspx", true);
                }
               
                else
                {
                    Server.Transfer("NewUserMainPage.aspx", true);
                }


                MyConnection.Close();
            }
        }

       
        }

        
    }
 
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