I was going to use ELMAH for our ultimate automatic error logging but recently realized that ASP.NET Health Monitoring does a same work (perhaps). Now I want to know (please) if they are alternatives of each other just like log4net and entlib?
ELMAH is for error monitoring, pure and simple. Easy to see the errors via a readout, RSS feeds, etc. Health monitoring is more of a full instrumentation solution.
Want the easy answer?
Look at how to setup Health Monitoring
Look at how to setup ELMAH
ELMAH is a very quick pluggable solution for error monitoring it has a very specific task (that is does beautifully). Health Monitoring is more of the shotgun see/monitor everything approach and involves much more setup work. Oh yeah, need to make a change? It's open source, grab it, change it as you like.
I have not used Health Monitoring in ASP.NET but I have used ELMAH and it is simply amazing. It literally takes only 2 minutes to setup and then you can see all the errors. There are also so many options to display the errors. Try out ELMAH you are going to love it.
ASP.NET Health Monitoring will automatically generate messages for events like app domain startup and shutdown and heartbeats and many other information about the web application. Logging frameworks don't support such features, but you can route the Health Monitoring system events to your logging framework of choice. Some frameworks even support this out of the box, such as CuttingEdge.Logging. Here is an configuration example of a CuttingEdge.Logging where the health events are forwarded to a logging provider:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging"
type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<system.web>
<healthMonitoring heartbeatInterval="0" enabled="true">
<providers>
<!-- We're configuring the web event provider here. -->
<add name="LoggingWebEventProvider"
type="CuttingEdge.Logging.Web.LoggingWebEventProvider, CuttingEdge.Logging"
loggingProvider="DebugLogger" />
</providers>
<rules>
<add name="Custom Event Provider"
eventName="All Events"
provider="LoggingWebEventProvider"
profile="Default" />
</rules>
</healthMonitoring>
</system.web>
<logging defaultProvider="DebugLogger">
<providers>
<!-- Configure your favorite provider here. -->
<add name="DebugLogger"
type="CuttingEdge.Logging.DebugLoggingProvider, CuttingEdge.Logging"
description="Debug logging provider"
threshold="Debug" />
</providers>
</logging>
</configuration>
Related
I'm using a third party CMS which is using a custom SessionStateProvider which is inheriting from System.Web.SessionState.SessionStateStoreProviderBase. System.Web.SessionState.SessionStateModule is used as SessionStateModule.
I need to allow concurrent request per session with a writable session. This can be done using the aspnet:AllowConcurrentRequestsPerSession setting when using the AsyncSessionStateModule from here. This would meet my requirement but this requires the provider to inherit from Microsoft.AspNet.SessionState.SessionStateStoreProviderAsyncBase and the provider from the third party CMS does not.
I understand this can be achieved by implementing ISessionStateModule but this seems high risk and easy to get wrong. Is there already a SessionStateModule somewhere which meet my requirements (it seems like I cannot be the first to run into this issue)?
Allows concurrent requests per session
Writable session (i.e. no SessionStateBehavior.ReadOnly to achieve concurrent request)
Supports a provider inheriting from System.Web.SessionState.SessionStateStoreProviderBase
Or am I missing something here and can this be achieved in an easier way?
I have used the Microsoft.AspNet.SessionState.SessionStateModule in a couple of different scenarios.
Microsoft.AspNet.SessionState.InProcSessionStateStoreAsync - This provider is included in the NuGet package and is a lot simpler to use as it does not require an external dependency. However, you need to ensure the user is hitting the same web-server. If you have a multiple server deployment, this requires "sticky sessions" on the load balancer.
Microsoft.Web.Redis.RedisSessionStateProvider - This provider requires 2 additional NuGet packages (Microsoft.Web.RedisSessionStateProvider and StackExchange.Redis) and an instance of Redis. While Redis is indeed very powerful, it may take some tweaking to get running smoothly. Do an internet search for "StackExchange Redis Timeout" and you will see a common problem that people face with this driver. I would only recommend this configuration in a multiple server configuration where you do not have "sticky sessions" on your load balancers.
Example web.config settings:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:AllowConcurrentRequestsPerSession" value="true" />
</appSettings>
<system.webServer>
<modules>
<remove name="Session" />
<add name="Session" type="Microsoft.AspNet.SessionState.SessionStateModuleAsync" preCondition="integratedMode" />
</modules>
</system.webServer>
<!-- Option 1: InProcSessionStateStoreAsync -->
<sessionState mode="Custom" customProvider="InProcSessionStateStoreAsync" cookieless="UseCookies">
<providers>
<add name="InProcSessionStateStoreAsync" type="Microsoft.AspNet.SessionState.InProcSessionStateStoreAsync" />
</providers>
</sessionState>
<!-- Option 2: RedisSessionStateProvider -->
<sessionState mode="Custom" customProvider="RedisSessionStateProvider" cookieless="UseCookies">
<providers>
<add name="RedisSessionStateProvider" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="..." />
</providers>
</sessionState>
</configuration>
As a side note, it looks like the AspNetSessionState project may already come with CosmosDB and Sql providers. YMMV - But you could try one of those if you wanted an external state server other than Redis. I ended up going with Redis mainly because it was used elsewhere in my app.
Objective:
I want to create a web service that allows me to connect to it (through ASP.NET Web Application) and then authenticate users just as Membership Provider Does/Role Provider Does.
I do not want to use Membership/Role Provider by configuring at the ASP.NET Web Application's Web.config. Instead, what i would like, is to have some sort of configuration that points my Asp.net Web Application to a webservice (the one i want to create), that than authenticates the user.
Expected Solution:
what i found after some google research, that the solution might be: WCF Authentication Service. But I am unable to get it working. I created this service, did all the configuration as it says in this article:
http://msdn.microsoft.com/en-us/library/bb398990.aspx
but i am not sure, how do i now configure my Asp.Net Web Application, to use this service as the Membership/Role Provider.
I may be going in complete wrong direction, and this service may not be the solution to my problem. Can you please help me out.
Thanks,
Your Dev Brother ... :)
You are going in the right direction.
ClientFormsAuthenticationMembershipProvider is a membership provider you are looking for.
Below is sample web.config configuration to use it:
<appSettings>
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<clear/>
<add name="ClientAuthenticationMembershipProvider"
type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
serviceUri="http://localhost:49712/Authentication_JSON_AppService.axd" />
</providers>
</membership>
</system.web>
Configuration may be tricky. I spent hours before figure out that ClientSettingsProvider.ServiceUri should be added.
You may add temp WinForms or WPF project to your solution to build configuration. these types of projects have special tab - Services tab in project settings that provide GUI for configuration. Sample below is for .NET 3.5 but idea is the same for 4.0.
http://www.codeproject.com/Articles/27670/Implementing-Application-Security-with-Client-Appl
I'm submitting a request to a web service, but I'm receiving some errors. They've asked to see an example of the xml request and response. I used Visual Studio to consume the web service, so I'm just calling a method in my code - I don't actually see any xml.
Is there a way to grab the XML request and response as XML or at least a text string?
Thanks
The easiest way to do this is using a 3rd party tool, like Fiddler . You'll be glad you started using this tool anyway.
You could use Fiddler.
I had to debug what was going across the line recently and tools like wireshark and fiddler are great tools for debugging the request and response unless you are using HTTPS or you are debugging on your local machine and executing the client and the web service locally.
I found a method that allows you to see the details of both the request and response without having to modify a single line of your code.
.NET has a feature built in called tracing. By enabling tracing for the System.NET namespace you can capture everything.
Here are the steps to enable.
Add the following code to your app.config in your client applications.
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.Net">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="System.Net"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="System.Net.trace.log" />
</sharedListeners>
<switches>
<add name="System.Net" value="Verbose" />
</switches>
</system.diagnostics>
Now when you execute your client application you can go into the folder that your executable was run from and find the file System.Net.trace.log
You will then find in the log file your request and the servers response. The great thing about this solution is you do not have to install or run anything extra. However the solution is probably only a solution for developing or diagnosing something in test or stage environment rather than production. However I am assuming because you mention creating the solution in Visual Studio and it not working that you are clearly in the development stage.
I have a WCF service than in my development and production environments works without any trouble but in my test environment it will occasionally throw a CommunicationObjectFaultedException. This has been very difficult to track down but it seems to happen only after going a long time with out calling it.
The client is a web applictaion running on two load balanced servers, the WCF service is hosted in IIS and running on two load balanced servers.
There is no difference in the WCF configuration between the three environments so I believe there must be something different in the way the servers are set up. What are some things I can ask my server admins to check? (I don't have proper access to these servers to check stuff myself).
You may want to enable tracing on the server in order to get more detailed error information. Can you ask your admins to enable that?
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
MSDN link here. I'll update my answer for any additional information you can post.
Good luck!
We use ELMAH error exception logging in our application. I'd like to keep ELMAH secure from regular users while still making it available to administrators/developers of the application.
When you set security with forms authentication in the web.config you then lose the ability to access the RSS feed. I'd like to be able to secure ELMAH but yet still pass through authentication to the axd to be able to access the RSS feed (i.e. /elmah.axd/rss) from a RSS reader.
Thinking that http authentication would be proper as then I can probably get to the rss feed with the following url syntax http://username:password#somedomain.com/elmah.axd/rss I assume you would need to set authentication mode="windows" on that specific path in the web.config. One issue pops up though is how do you set credentials on a virtual file?
Looking at Google brings back this article on CodeProject on how to set up authentication passthrough with cookies. Is this a good solution to my problem?
Is there another way that is better to be able to access the RSS feed while still being secure?
Thanks.
Supporting HTTP Authentication and Forms Authentication in a Single ASP.NET Web Site
Basically you add a dll called MADAM to your project adjust your web.config and configure which file(s) you want to authenticate as Basic instead of Forms:
<configuration>
<configSections>
<sectionGroup name="madam">
<section name="userSecurityAuthority" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="formsAuthenticationDisposition" type="Madam.FormsAuthenticationDispositionSectionHandler, Madam" />
</sectionGroup>
</configSections>
...
<madam>
<userSecurityAuthority ... />
<formsAuthenticationDisposition>
<discriminators all="[true|false]">
...
</discriminators>
</formsAuthenticationDisposition>
</madam>
...
<system.web>
<httpModules>
<add name="FormsAuthenticationDisposition" type="Madam.FormsAuthenticationDispositionModule, Madam" />
<add name="AuthenticationModule" type="MADAM Authentication Module Type" />
</system.web>
</configuration>
This was easy to set up and solved my problem of being able to authenticate elmah.axd and still be able to subscribe to the RSS feed with Basic authentication credentials.
Side note MADAM is written by the same guy that wrote ELMAH, coincidence?
Depends on the client I guess - I know some desktop readers (sure others do, as well) support feeds that require authentication, and provide a login box when first requesting it - not sure what they are doing behind the scenes to make it work though.