I am involved in designing a asp.net webforms application using .NET 3.5. I have a requirement where we need to log exceptions.
What is the best approach for exception handling, given that there would be concurrent users for this application?
Is there a need or possibility to log in exceptions at a user level? My support team in-charge wants to have a feature where the support team can get user specific log files.
To give you a background, this application is currently on VB 6.0 and we are migrating it along with some enhancements. So, today the support personnel have a provision to get user specific log files.
My vote is for ELMAH. It is the easiest to set up and automagically lets you find bugs that never get reported back from the end-user.
While this is a bit self promotion, CuttingEdge.Logging allows native support for logging the user name in who's context a log event occured. When you configure the AspNetSqlLoggingProvider with the userNameRetrievalType set to "Membership", it allows retrieving the user name from from the HttpContext.
The AspNetSqlLoggingProvider logs to a database. The framework does not contain any tools for analyzing logs. When you want this, you can take a look at ELMAH, and I believe there are tools (both open source and commercially) available for log4net.
Good luck.
Related
I am building website, which is using ASP.NET, MS-SQL and AJAX.
I wonder, what is the best way to log errors in the entire website?
What I was thinking about, is just create some global log class (accessible from entire application) and log errors to "asperror.txt" file using try catch blocks in asp.net.
Is this good way to track errors? Maybe there is some better ways?
Thank you.
My humble opinion, and to not to reinvent the wheel, is to use ELMAH, which is great and easy to configure in ASP.NET.
It allows logging to Database, File, Email and so forth. It catches all unhandled exceptions and even allows you to see the last X (certain buffer is available, I believe is 500) number of messages through a web page. It even has a RSS feed if you want to subscribe to it.
Use ELMAH:
ELMAH with initial configuration for getting started quickly. ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.
I'm trying to debug an ASP.NET MVC application which uses the .NET 4.5 version of WIF to provide user identity. As those claims are being generated by a remote STS specific for that user, it's hard to test which claims are being received for a given user in an development environment.
What I would like is a mechanism that will allow me to see a user's claims by looking over their shoulder as they use the system. I immediately thought of the ASP.NET WebForms trace system as a source of tracing information and a convenient mechanism to display it, but I don't know of an equivalent in ASP.NET MVC.
Are there any built-in mechanisms to expose this information to me whilst debugging with a tester?
Options
Glimpse- like webform inpage trage/trace.axd on steroids. Works nice for MVC apps, has little to offer webforms though (the team has been promising big things though, it's an area to watch).
trace.axd - Trace.Write output should appear here, I've never tried to run it on a busy server. Access to trace.axd should work for an mcv app, not sure if inpage trace works for mvc-- I would guess not but I have never tried.
<% "Some trace" %> -- I sometimes dump diagnostics to all screens and put it in the footer, or put it in the footer then make the text white on white, so I can instruct the user on how see it and copy it, but they won't normally see it.
System.Diagnostics TraceSource and associated classes -- It's better than Trace.Write but has some flaws if you use trace a lot. Still, there are scenarios when you can't assume your favorite trace/logging library will be available. If I were to use this, I'd write a custom listener and write to your user's diagnostic data to the database, or a file, listeners already exist for files.
Log4Net -- a trace/logging framework. Supports writing to a variety of places-- console, database, file, etc. Has fewer design flaws that System.Diagnostics, but requires adding noe more dependency to your app. Use same as System.Diagnostics -- log to a file or database and inspect your users STS values there.
I've never had the good fortune of using WIF or STS, but I imagine that pretty printing an object and it's properties is the same for much any object. You may want to post a WIF/STS question separately if you need to know how to extract a particular piece of info from it.
Well - Trace.Write data shows up in the output window in VS while debugging. Maybe thats good enough. You can also add a trace listener for the System.IdentityModel trace source to get more insight into the token/claims processing.
I have a usermanagement table into my sql server 2008 i want to check each user with their particular role frm my database & not from asp.net predefined database. please help me with the code for the same. also what i need to change into my web config file.
You probably want to implement (roll your own) version of the membership provider to make this job easier, more secure and less error prone - it will also save you writing tons of additional plumbing code.
In essence it means implementing the IIdentity and IPrincipal interfaces (Sounds scary but its really not that bad). See this blog here http://www.bradygaster.com/custom-authentication-with-mvc-3.0 for a step by step guide. Additionally it is worth reading the comments and links to enable proper Forms Authentication via Auth Cookie rather than the basic session management referenced directly in the post!.
Also note this example on the blog is for MVC 3 BUT its equally applicable to Web Forms projects too.
Recently created a MVC2 Portal but now I want to add a couple of models that call out to other processes such as powershell in order to run some tasks for the user and return the results.
All the examples I've found show the MVC model binding to SQL so the question is can MVC be used for what I'm asking of it and if so does anyone know of some examples that I can look at etc.
Any suggestions or comments are appreciated.
Closed due to lack of response, will look at doing a custom model which talks to powershell runspace.
All things are possible, but I suspect the issue you're going to have is that of security and the user account that you're running your website under.
Generally, the AppPool that an IIS website runs under is set up to run as Network Service or as some other account that has limited access to the file system. That service generally doesn't have it's profile (Desktop) loaded either.
You can certainly run the AppPool as a local account, and can load that user's profile (these settings are found in IIS manager) but by doing that you need to understand the security implications.
Having given you this "health warning" one example of hosting powershell in ASP.NET can be found here...
http://www.leastprivilege.com/HostingPowerShellInASPNET.aspx
... and another slightly longer one here...
Link
I'd like to be able to view the event log for a series of asp.net websites running on IIS. Can I do this externally, for example, through a web interface?
No, but there are two solutions I would recommend:
Adiscon EventLogger is a third-party product that will send your Windows EventLog to a SQL database. You can either send all events or create filters. Of course, once the events are in a SQL database, you can use any of the usual tools to create a web interface.
You can use ASP.NET's HealthMonitoring configuration section to configure .NET to send all ASP.NET-related events directly to a SQL database. This covers exceptions, heartbeats, and a host of other event types. The SqlWebEventProvider is a cinch to setup.
Do you want to know if you can home-roll something or are you looking for an app you can get off the shelf?
I'm not a Windows guy, but I think Microsoft's MOM/SCOM solution will probably let you view the event log over a web UI - probably really heavy and expensive if that's all you need though.
A quick google found http://www.codeproject.com/KB/XML/Event_Logger.aspx which shows that you can get in if you want to roll your own... also an MS tool on msdn
Sorry I can't be more help