I am using Global.asax page for error handling. While there is an error I want to transfer to a Error page to show a friendly message. But it is not showing that page.
Have you tried like this:
public class Global : System.Web.HttpApplication
{
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Context.Server.GetLastError().GetBaseException();
// TODO: Do something with the exception
Context.Response.StatusCode = 500;
Context.Server.Transfer("~/500.htm");
}
}
make sure ur file exist... ShowErrorPage.htm
try respone.redirect instead of server.transfer like....
Exception exception = Context.Server.GetLastError().GetBaseException();
Response.Redirect("~/ShowErrorPage.htm");
Related
Iam tried to hide a div which is placed in master page,but i got an error like this "Object reference not set to an instance of an object".
My codes
<div runat="server" id="cnms">
Cinemas
</div>
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AdminMaster admns = new AdminMaster();//This si my admin page
admns.FindControl("cnms").Visible = false;//I got error here
}
}
What went wrong for me?any solution?
The approach you are using is instantiating a new instance of the masterpage, which when you do that it all of the control references are null. You need to use the existing master page instance, using the Page.Master property like the following:
protected void Page_Load(object sender, EventArgs e)
{
AdminMaster admns = (AdminMaster)Page.Master; //This si my admin page
admns.FindControl("cnms").Visible = false;//I got error here
}
I have this weird thing going on in my application.
At the moment, I have 'Trace="true" on my aspx directive and all Response.Redirect() codes are working fine. But as soon as I remove this directive, all the Response.Redirect go to the Home page of the site.
Any help will be appreaciated.
Here's the code:
protected void SearchSubmit_Click(object sender, EventArgs e) {
Response.Redirect( "~/?view=Search+results&search=" + Server.UrlEncode(SearchText.Text), true);
}
protected void AdvSearchSubmit_Click(object sender, EventArgs e) {
string filtertype = ""; if (rbFilter.SelectedValue != "") filtertype = "&f=" + rbFilter.SelectedValue; Response.Redirect("~/?view=Search+results&search=" + HttpUtility.UrlEncode(advSearchText.Text) );
}
I'll bet an exception is occuring and you're being redirected to the home page via your application_error method in Global.asax.
Since response.redirect() aborts the thread this is the likely outcome.
I don't know why the Response.Redirect not working properly when I deploy my code to IIS7? The white/yellow error page always get displayed instead of my Errors.aspx. But when debug running using Visual Studio on my computer, it runs just fine?
protected void Application_Error(object sender, EventArgs e)
{
ILog log = LogManager.GetLogger(typeof(Global).Name);
Exception objErr = Server.GetLastError().GetBaseException();
log.Error(objErr);
string err = "Error Caught in Application_Error event\n" +
"\nError Message:" + objErr.Message.ToString() +
"\nStack Trace:" + objErr.StackTrace.ToString();
EventLog.WriteEntry("Kiosk", err, EventLogEntryType.Error);
Server.ClearError();
Response.Redirect("~/Error.aspx", false);
}
I had the same problem and solved it with:
HttpContext.Current.ClearError();
Response.Redirect("~/Error.aspx", false);
return;
HttpContext.Current.Server.ClearError();
HttpContext.Current.ClearError();
====================================================================
Redirect to NEW VIRTUAL! directory (Error)
HttpContext.Current.Response.Redirect([http://localhost:8990/Error/ErrorPageServer.aspx]);
For me the below code worked.
HttpContext.Current.Server.ClearError();
HttpContext.Current.Response.Redirect("~/ErrorPage.aspx");
protected void Application_Error(object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().InnerException;
//Logging.WriteToErrorLog("Error Caught in Application_Error event", objErr);
HttpContext.Current.Server.ClearError();
HttpContext.Current.Application.Add("test", objErr);
HttpContext.Current.Response.Redirect("~/Home/Index");
return;
}
Try to turn off the CustomError in web.config. It will give you more specific about the error details. Maybe it doesn't the error from Response.Redirect.
I got the problem in Crystal Report- Error Messsage:Load report failed.
how to solve this issue??.
You can call show data on report in DataBinding and Navigate methods.
protected void CrystalReportViewer1_DataBinding(object sender, EventArgs e)
{
this.ShowReportData();
}
protected void CrystalReportViewer1_Navigate(object source, CrystalDecisions.Web.NavigateEventArgs e)
{
this.ShowReportData();
}
If your report is running for awhile and then falls over make sure you Dispose it.......
if(myReport != null)
{
myReport .Close();
myReport .Dispose();
}
I've implemented Rick Strahl's GZipEncodePage method on my site and it works great for the site itself. However, when my code throws an exception the "Server Error" page looks something like this:
(source: x01.co.uk)
I've tried to hooking into Application_Error in an effort to remove the GZip headers but to no avail. How I can reverse the GZipping on error?
I'm understand that this question is really outdated.
On Application_Error remove Filters from Response, like this
protected void Application_Error(Object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
app.Response.Filter = null;
}
Hope this helps anybody.
In my case I put this in the my basepage class like so:
public class BasePage : System.Web.UI.Page
{
protected override void OnError(EventArgs e)
{
base.OnError(e);
System.Web.HttpContext context = System.Web.HttpContext.Current;
if (context != null && context.Response.Filter != null)
context.Response.Filter = null;
}
}