Hi
I may be repeating this question. i deliberately changed Stored Procedure Name in class GetAllLocation. I am able to Log error message in Database.
But i wamt that some message should also get displayed to user. With this code it is not displaying any message to User.
Global.asax
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
if (exception != null)
{
Response.Clear();
HttpException httpException = exception as HttpException;
if (httpException != null)
{
string action = "Index";
// clear error on server
Response.Clear();
Server.ClearError();
Response.Redirect(String.Format("~/Error/{0}/?message={1}", action, exception.Message));
}
}
}
public class ErrorController : Controller
{
public ActionResult Index(string message)
{
ViewBag.ErrorMessage = message;
return View();
}
}
Error Index
Index
@ViewBag.ErrorMessage
Below is the Class
public List GetAllLocation()
{
List objLocation = new List();
try
{
using (SqlConnection con = new SqlConnection(Common.Con))
{
con.Open();
SqlCommand cmd = new SqlCommand("sp_Location1", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Action", "R");
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
objLocation.Add(new Location
{
Id = rdr["Id"].ToString(),
Description = rdr["Description"].ToString(),
IsActive = Convert.ToBoolean(rdr["IsActive"]),
});
}
}
}
catch (Exception ex)
{
ExceptionLogging.SendExcepToDB(ex);
}
return objLocation;
}
Thanks
Ramco RamcoPosted Jul 9, 2021, 3:51 AM
Sachin SinghPosted Jul 8, 2021, 5:07 PM
Sachin SinghPosted Jul 8, 2021, 4:17 PM
ExceptionLogging.SendExcepToDB(exception.Message);Ramco RamcoPosted Jul 8, 2021, 4:07 PM
Sachin SinghPosted Jul 8, 2021, 3:59 PM