ASP.NET MVC pass parameter to stored procedure from controller without Entity Framework
<p>ASP.NET MVC newbie here from a Webforms background. I'm trying to pass the logged in username value via <code>HttpContext.User.Identity.Name</code> to a stored procedure. I'm basically trying to check if the <code>Username</code> exists in the database table or not. I think I'm overlooking something as I'm not quite sure how to pass the <code>User.Identity.Name</code> value to the stored procedure so that it executes and returns a value that either exists or <code>null/blank</code>. Here's my code: </p>

<p>Data access layer class: </p>

<pre><code>    public LoggedUser GetLoggedUser(LoggedUser obj)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["HWebb"].ConnectionString);
        string UserName = "";

        try
        {
            SqlParameter[] parameters ={
                     new SqlParameter("@USER_CRED",obj.User_Name),
                                       };
            SqlCommand cmd = CreateCommand("PortalWeb.GetSelect_User", parameters, con);

            DataTable dt = new DataTable();

            con.Open();
            SqlDataAdapter ada = new SqlDataAdapter(cmd);
            ada.Fill(dt);

            foreach (DataRow dr in dt.Rows)
            {
                if (dr["USER_CRED"] != DBNull.Value)
                    UserName = Convert.ToString(dr["USER_CRED"]);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            con.Close();
        }

        return obj;
    }
</code></pre>

<p>Model:</p>

<pre><code>public class LoggedUser
{
    public string User_Name { get; set; }
}
</code></pre>

<p>Controller:</p>

<pre><code>public ActionResult UserVerification()
{
        DataAccess dac = new DataAccess();
        LoggedUser objUser = new LoggedUser();
        objUser = dac.GetLoggedUser(objUser);

        if (HttpContext.User.Identity.Name != objUser.User_Name)
        {
            return RedirectToAction("Index", "Home");
        }
        return null;
}
</code></pre>

<p>This won't cause any errors, but I don't think the parameters are being passed correctly as the table returns a <code>null</code> value and I'm not sure if the <code>HttpContext.User.Identity.Name</code> value is even being passed in the first place. </p>

<p>Is there a way to pass the value from the controller to the stored procedure? I'm new to this so I'm sure there I'm missing some code to have this fully functional. I hope someone can help. </p>

<p>Thanks!</p>