Hi
In below code while dr.read i have given wrong value docentr . Error message should get displayed and quit the application.
docentry = (rdr["docentr"]).ToString();
Function is being called from here
if (!Page.IsPostBack)
{
if (Common.CommonFunction.AuthenticatedUser().Item1) // Check if the user is authenticated
{
hdfLoginId.Value = Common.CommonFunction.GetUserInfo().Item1;
var userId = Common.CommonFunction.GetUserInfo().Item2;
var userRole = Common.CommonFunction.GetUserInfo().Item3;
GetData();
}
}
public static Tuple GetUserInfo()
{
try
{
//1 - Docentry
//2 - User ID
//3 - User Role
//4 - User Active
using (SqlConnection con = new SqlConnection(Common.CommonFunction.cnn_Live))
{
SqlCommand cmd = new SqlCommand("select userid from users where userid = '" + (AuthenticatedUser().Item3) + "'", con);
cmd.CommandType = CommandType.Text;
con.Open();
string userid = "";
object result = cmd.ExecuteScalar();
if (result != null)
{
userid = result.ToString();
SqlCommand cmd0 = new SqlCommand("select top 1 * from users where userid = '" + userid + "'", con);
cmd0.CommandType = CommandType.Text;
string docentry = "";
string userrole = "";
string status = "";
SqlDataReader rdr = cmd0.ExecuteReader();
while (rdr.Read())
{
docentry = (rdr["docentr"]).ToString();
userrole = rdr["UserRole"].ToString();
status = rdr["Status"].ToString();
}
return Tuple.Create(docentry,userid, userrole, Convert.ToBoolean(status));
}
else
{
return Tuple.Create(string.Empty,string.Empty, "User", false);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return Tuple.Create(string.Empty, string.Empty, string.Empty, false);
}
}
Thanks
Gowtham CpPosted Aug 21, 2024, 3:52 PM
Sorry for the mix-up. Using
Environment.Exit(1)will shut down the entire server, which isn't ideal for web apps. Instead, you should handle errors by redirecting users to an error page or displaying an error message.1. Update
GetUserInfo:Error Page :
Ramco RamcoPosted Aug 21, 2024, 1:42 PM
Hi
I am using .net web application. Will the below line will work
Environment.Exit(1);
Thanks
Gowtham CpPosted Aug 21, 2024, 1:33 PM
Replace your
GetUserInfomethod with this:Changes Made:
docentryis valid and handle cases where user data isn’t found.Environment.Exit(1)for a clean exit on errors.