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
C#
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));
}
}
}C#
public class ErrorController : Controller
{
public ActionResult Index(string message)
{
ViewBag.ErrorMessage = message;
return View();
}
}Error Index
Code
Index
@ViewBag.ErrorMessageBelow is the Class
C#
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

Sachin SinghRank #66 · 26.2K reputationPosted Jul 8, 2021, 12:17 PM EDT
ExceptionLogging.SendExcepToDB(exception.Message);Sachin SinghRank #66 · 26.2K reputationPosted Jul 8, 2021, 11:59 AM EDT
Ramco RamcoRank #462 · 5.4K reputationPosted Jul 8, 2021, 12:07 PM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jul 8, 2021, 1:07 PM EDT
Ramco RamcoRank #462 · 5.4K reputationPosted Jul 8, 2021, 11:51 PM EDT