I am trying to log the entire exception to the IIS log in the following way:
public void OnTransientFaultOccurred(object sender, RetryingEventArgs e)
{
_httpResponse.AppendToLog(string.Format("RetryCount:{0}", e.CurrentRetryCount));
_httpResponse.AppendToLog(string.Format("NextRetryIn:{0}ms", e.Delay.TotalMilliseconds));
_httpResponse.AppendToLog(string.Format("Exception:{0}",e.LastException));
}
But the log only shows '...'.
Is there any limit in terms of how much data can be written to the log ?
One thing to try: Make sure the advanced logging extension is enabled.
As per Append custom value to IIS logs from ASP.NET.
Related
i try to show ssrsc reports in asp.net web page using report viewer
code
protected void Button1_Click(object sender, EventArgs e)
{
ReportViewer2.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
ReportViewer2.ServerReport.ReportServerUrl = new Uri("http://lenovo-pc/ReportServer");
ReportViewer2.ServerReport.ReportPath = "/Report Project1/Report1";
ReportViewer2.ServerReport.Refresh();
}
where is the probelm... and why report not display?
It tells you the problem in the error message:
Login failed for 'administrator'
The account that you are trying to run the report under does not have access to the database or table that DataSource1 is trying to connect to.
Note that, for security reasons, connection credentials do not propagate when you deploy a report. You may need to set these up for that report on the server that it is deployed to.
Alternatively, you may need to pass the appropriate credentials as part of your code when you run the report.
I am having a huge website with over 100 single sites in ASP.Net.
Of course I try to catch every action with a try-catch block or with other things like validation-controls.
But I want, IF a error happens which I get not catched to happens following:
1) Write the Error in Database
2) Show user a specific site instead the errorsite from asp.net
How to do that?
You can use the Application_Error event handler in in Global.asx to handle any exceptions that are not caught at the page level. See, for example,
http://msdn.microsoft.com/en-us/library/24395wz3(v=vs.100).aspx
It's kind of up to you what you do in the event handler, so you can log the error to a database if you want to. You can also redirect to another page of your choosing to display the error however you want.
Note that the Application_Error event will be raised for all uncaught exceptions, including Http exceptions (e.g. 404 Not found). You probably don't want to log those.
You should try ELMAH
Check out the blog post of Scott Hanselman on how to integrate it in asp.net website and make it work.
Below is the article from Scott Mitchel on how to log errors with Elmah and how to show custom error page to user:
http://www.asp.net/web-forms/tutorials/deployment/deploying-web-site-projects/logging-error-details-with-elmah-cs
http://www.asp.net/web-forms/tutorials/deployment/deploying-web-site-projects/displaying-a-custom-error-page-cs
If you not into trying elmah, which is a breeze to setup. It depends on how your 100 sites are setup. But you possibly could look into using the global
Application_Error event in global.asax.cs and add you own handling code in there.
protected void Application_Error(object sender, EventArgs e)
{
var lastException = Server.GetLastError();
//log it to db, re-route the request to an alternate location ... etc
}
Another option, again it depends on how your sites are setup/hosted would be to read the event_log on the server, and check for ASP.NET errors saving the relevant details to the db.
I have made a custom error page for my ASP.NET 4 application. I put the exception object in HttpContext.current.Session["CustomError"] but when the user is redirected to the error page HttpContext.current.Session["CustomError"] is null.
I do it in CustomError class constructor like this:
public CustomError(enExceptionType ExceptionType) : base(ExceptionMessage(ExceptionType)) {
HttpContext.Current.Session["CustomError"] = this;
}
when I step over the code Session["Error"] contains the error object.
any idea?
UPDATE:
I removed custom error page from web.config and added this to glabal.asax:
void Application_Error(object sender, EventArgs e)
{
if (Context.IsCustomErrorEnabled)
{
Response.Redirect("~/Error.aspx");
}
}
by stepping through this function I noticed that when an exception is thrown this function is called two time, the first time Session["CustiomError"] contains the error object but the second time its null.
Instead of using Response.redirect(URL) (which I assume you have in your code) use
Server.Transfer(URL)
or
Response.redirect(url, false)
Why Server.Transfer(url)?
Transferring to another page using
Server.Transfer conserves server
resources. Instead of telling the
browser to redirect, it simply changes
the "focus" on the Web server and
transfers the request. This means you
don't get quite as many HTTP requests
coming through, which therefore eases
the pressure on your Web server and
makes your applications run faster.
Source here.
Please let me know if one of these works for you.
UPDATE:
If you use a web config setting can you try adding ResponseWrite value to redirectmode var?
<customErrors mode="RemoteOnly" defaultRedirect="~/errors/GeneralError.aspx" redirectMode="ResponseRewrite" />
If this is still not working I suggest to implement this (I've done it in my application to log the errors in log files (for me as admin) and present a generic error to the user).
This solved the problem, but I would appreciate it if someone tells me why :)
void Application_Error(object sender, EventArgs e)
{
if (Context.IsCustomErrorEnabled)
{
Response.Redirect("~/Error.aspx");
**Server.ClearError();**
}
}
We're having a load of problems with an ASP.Net Membership application at the moment.
For reasons that aren't relevant, we're using a MembershipProvider implementation that uses the old-style Web.config specified credentials and a RoleProvider that just allows everything (the RolesProvider may be the problem here!). This isn't something we can change, as it's a somewhat hacky workaround to some other issues we've been experiencing and we just want to get this minimal case working.
The MembershipProvider implementation is working beautifully and everything works fine when I test it on my machine. When I push it to the testing server, though, I authenticate successfully (and can see the cookie in the trace log), but then get bounced straight back to the login page, as can be seen with these entries from the trace log:
19 9/7/2010 5:50:03 PM /login.aspx 302 POST View Details
20 9/7/2010 5:50:03 PM /Default.aspx 302 GET View Details
21 9/7/2010 5:50:03 PM /login.aspx 200 GET View Details
Having added lots of Tracing to the code, that I genuinely am authenticating successfully:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
LoginControl.LoggedIn += new EventHandler(LoginControl_LoggedIn);
LoginControl.LoginError += new EventHandler(LoginControl_LoginError);
}
void LoginControl_LoggedIn(object sender, EventArgs e)
{
Trace.Write("LoginControl_LoggedIn", "Logged in successfully");
}
void LoginControl_LoginError(object sender, EventArgs e)
{
Trace.Write("LoginControl_LoginError", "Failed to authenticate");
}
gives me:
LoginControl_LoggedIn Logged in successfully 0.0044027241880433 0.000238
Having tried tracing in the Default.aspx that I get redirected to, not even the PreInit event fires.
I don't think it's the RoleProvider that's the problem, partly because it really is just saying yes to everything:
public override bool IsUserInRole(string username, string roleName)
{
return true;
}
I've looked at SO:62013, Forums:1318557 and the blog post mentioned in SO:62013 and none of those makes any difference.
Any thoughts, anyone? I'm totally at a loss.
Have you tried enabling .NET Framework source stepping in Visual Studio?
Tools > Options > Debugging > (uncheck) Enable Just My Code
and
Tools > Options > Debugging > Enable .NET Framework source stepping
You then have to import the .NET symbols from the Microsoft Symbol Servers, but it guides you through it. You might at least then be able to step through the base Role and Membership providers to see if they are doing the redirect.
This isn't really an answer (would have preferred to leave it as a comment, but don't have enough rep. yet)
Try working through the troubleshooting steps found here:
Troubleshoot Forms Authentication
Hopefully you find your problem there. The only other suggestion I have at the moment is disabling the role provider in the web.config (if possible) and trying it that way.
I want to save each request to the website. In general I want to include the following information:
User IP, The web site url, user-if-exist, date-time.
Response time, response success-failed status.
Is it reasonable to collect the 1 and 2 in the same action? (like same HttpModule)?
Do you know about any existing structure that I can follow that track every request/response-status to the website?
The data need to be logged to sql server.
Look in your web server logs.
How about IIS logs? they already have all the data items you listed so far
In BeginRequest Method you need to write the following code.
protected void Application_BeginRequest(object sender, EventArgs e)
{
//String s = HttpContext.Current.Request.Path;
//HttpContext.Current.RewritePath("Login.aspx");
String referrer = HttpContext.Current.Request.UrlReferrer;
String sourceIP = HttpContext.Current.Request.UserHostAddress;
String browser = HttpContext.Current.Request.UserAgent;
}