I'm working out an implementation of ELMAH in a web application that logs exceptions to a SQL Server. That's inconsequential, however. My goal is to include the application name in the log so I can easily identify the offending application at a glance when checking error reports. I've searched far and wide spending hours trying to find a solution. I've included Application Name=[myApp] in my SQL Server connection string, but that only helps me to identify the app during a SQL Server trace and not in my actual error logging.
Has anyone done this? Here is an example of a log record in my database. I would like to see the Application Name listed as well. This happens to be the ELMAH implementation of the table, but it could just as well have been a custom table with the same field.
I would think this should be as simple as adding a value to the web.config or something, but I can't seem to find any solution like that or any other. I should probably also note that I'm using IIS 7.5 and .NET 4.0 in case that has anything to do with it. :)
Perhaps the responses to this question will help...
PS. Don't look at the accepted answer but the follow up where the <errorLog> element example is given...
As it is my practice to always fill out the assembly info for all my applications, I have elected to populate this field from My.Application.Info.Title which I just figured out how to access programmatically. To set this field in ELMAH, I set the ApplicationName value of my SqlErrorLog object like so:
Dim se As New Elmah.SqlErrorLog(ConnectionStrings("Elmah").ConnectionString)
se.ApplicationName = My.Application.Info.Title
The assembly info can be set by opening the project properties -> Application tab -> click Assembly Information... -> set "Title" value.
Now when you call the Log function for this object, it will create a database entry including the Application Name.
Related
I have a web app, using asp.net MVC Core, along with entity framework core. Part of this application has a simple setup table. This is just a table, which will only ever have one record, with a number of fields in, so the administrator can easily change how the web app works.
The setup table is loaded into a static "Settings" class, so anywhere in the application can read it (views and controllers)
What I want to know is when or how is the best place to load this. At the moment I'm loading it in Startup.Configure, after the routes have been set.
For the most part, this works fine. But if I add a field to the setup table, its impossible to migrate (I'm using code first). I get errors about invalid fields. Typically the errors look like this:
An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: One or more errors occurred. (Invalid column name 'EmailApiKey'.
Invalid column name 'EmailBaseUrl'.
Invalid column name 'EmailSenderAddress'.
Invalid column name 'EmailSenderDomain'.
Invalid column name 'EmailSenderName'.)
Unable to create an object of type 'ApplicationDbContext'. Add an implementation of 'IDesignTimeDbContextFactory<ApplicationDbContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.
To get around this, I have to remove the code thats loading the setup table.
This makes me think this is not the best place/way to load settings (seeing as though it obstructs with database migrations).
So - is there a better way to do this? Essentially, I want to:
load a setup table once when app first started.
Have this accessable everywhere in the application (views and controllers).
If a user changes the setup, the static version should be automatically updated.
I would lazy-load the settings on first access rather than at application startup. An advantage is that if the lazy-load fails, you'll just try again next time it's accessed.
If a user changes the setup, the static version should be automatically updated.
You could cache it in the ASP.NET Cache or MemoryCache. You can set an expiration so that it will be refreshed periodically in case a user has made changes. Or if the settings are in a SQL Server database, you can use the SqlCacheDependency class.
I get the following error with a legacy asp application that I have been asked to help out with.
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/site_manager/image_upload.asp, line 27
800401f3
The line ofcode that throws the error is shown below:
Set fbase = Server.CreateObject("chili.upload.1")
As you ahve probably guessed oldschool asp isn't my strong point but from the research I have done it seems as if a component hasn't been registered on the server (I only have FTP access).
What component needs to be regsistered?
Thanks for the help...
You're missing the registration of the DLL that creates the chili.upload.1 object. Are you trying to run this on a Linux machine?
You need to register the Sun Chili!Soft ASP components. Here's the manual on this from 2003:
http://ns7.webmasters.com/caspdoc/html/running_the_setup_program_sun_chili_soft_asp_for_windows.htm. Note that this only works if you still have the original setup. Otherwise you're out of luck. Sun Chili!Soft ASP is no longer available and very, very dead.
If you're just interested in file upload functionality on ASP, I can recommend Free ASP Upload. It requires no registration of any components and generally works. I can also recommend this article on the topic of ASP uploads. If you're willing to shell out some money there are hundreds of components that do the same thing too.
Register the DLL on your computer, and then do this:
Locate and then click the following registry subkey:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\
FeatureControl\FEATURE_IGNORE_ZONES_INITIALIZATION_FAILURE_KB945701
Note If the FEATURE_IGNORE_ZONES_INITIALIZATION_FAILURE_KB945701 subkey does not exist, you must manually create it. If you're using a 64 bit OS, you may need to use HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\ FeatureControl\FEATURE_IGNORE_ZONES_INITIALIZATION_FAILURE_KB945701 instead
Right-click FEATURE_IGNORE_ZONES_INITIALIZATION_FAILURE_KB945701,
point to New, and then click DWORD Value
Type w3wp.exe to name the new registry entry, and then press ENTER.
Right-click w3wp.exe, and then click Modify.
In the Value data box, type 1, and then click OK.
After setting this registry key, a simple app pool restart will apply the change. No longer will your .NET COM components randomly stop working with no real solution except shuffling application pools!
The challenge is to determine whether ASP.NET is enabled within IIS7 in a reliable and correct way.
Enabling/Disabling is done in this case by going into:
Server Manager ->
Roles ->
Web Server (IIS) ->
Remove Role Services ->
Remove ASP.NET
The natural place to determine this should be within the applicationHost.config file. However, with ASP.NET enabled or disabled, we still have the "ManagedEngine" module available, and we still have the isapi filter record in the tag.
The best I can find at the moment is to check if the <isapiCgiRestriction> tag includes the aspnet_isapi.dll, or that the ASPNET trace provider is available.
However these aren't detecting the presence of the ASP.NET config directly, just a side effect that could conceivably be reconfigured by the user.
I'd rather do this by examining the IIS configuration/setup rather than the OS itself, if possible, although enumerating the Roles & Services on the server might be acceptable if we can guarantee that this technique will always work whenever IIS7 is used.
Update
Thanks for the responses. Clarifying exactly what I want to do, I'm pulling settings from a variety of places in the server's configuration into a single (readonly) view to show what the user needs to have configured to allow the software to work.
One of the settings I need to bring in is this one:
The one highlighted in red.
I don't need to manipulate the setting, just reproduce it. I want to see whether the user checked the ASP.NET box when they added the IIS role to the server, as in this example they clearly didn't.
I'd like to do this by looking at something reliable in IIS rather than enumerating the role services because I don't want to add any platform specific dependencies on the check that I don't need. I don't know if it will ever be possible to install IIS7 on a server that doesn't have the Roles/Services infrastructure, but in preference, I'd rather not worry about it. I also have a load of libraries for scrubbing around IIS already.
However, I'm also having trouble finding out how to enumerate the Roles/Services at all, so if there's a solution that involves doing that, it would certainly be useful, and much better than checking the side effect of having the ASPNET trace provider lying around.
Unfortunately, if you don't check the ASP.NET button, you can still get the ManagedEngine module in the IIS applicationHost.config file, so it's not a reliable check. You can also have ASP.NET mapped as an isapi filter, so checking them isn't enough. These things are especially problematic in the case where ASP.NET was installed but has been removed.
It looks like the best solution would be to examine the Role Services. However, API information on this is looking pretty rare, hence the cry for help.
The absolute way to know if they checked that or not is to search the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Components
In there you should see two values set to 1, ASPNET and NetFxEnvironment and NetFxExtensibility. This registry key is the IIS Setup key that contains all the components that have been enabled in IIS.
Determining if asp.net is even an installed feature (prerequisite for enabling it) can be done through PowerShell, which implies there is .net api out there for it if you dig hard enough. The PowerShell methods:
Import-Module servermanager
Get-WindowsFeature web-asp-net
Which will return an object of type Microsoft.Windows.ServerManager.Commands.Feature. The installed property is boolean and indicates whether or not the feature is installed.
So do you want the easy way? Make a nice pretty .aspx page that displays as HTML with an error block in a div in a placeholder saying "You need to install ASP.NET" and have it change on ASP.NET being installed to instead say "ASP.NET is installed" and then just have the tool launch this webpage in the default browser after copying it to the directory identified in IIS as the *:80 site (or create the directory mapping in IIS programmatically by altering the XML and then removing it later)
May not be the most elegant but it does ensure that testing shows what features are truly installed versus what's in an XML file.
Because that will scream "do it the lazy ignorant way" I'll remind you that the only way for me to know in javascript what features I can use is to test them before I try to use them, or assume they're there and watch it blow up. My point is, it doesn't matter what gets reported in a file, it matters what you can actually use. Just because C:\Windows\Micrsoft.Net\Framework\v3.xxxxxxxx exists and has files doesn't mean the dll's are registered in the GAC, does it?
Just got ELMAH running, and so far it seems great. I am wondering two things:
I am using ELMAH from multiple applications, all logging to the same table in MSSQL. Will I be able to drop the .axd file in any project to browse all the logs, or will I need a custom solution? (The latter seems more likely, so I can have filtering options, but I'm just trying to verify.)
Is elmah.axd somehow customizeable? I'd rather modify it than write my own, so that I could add the ApplicationName column to its listing.
We just released our ELMAH based exception reporting solution on codeplex: http://aspexceptionreporter.codeplex.com/
One of the features is that it logs errors of multiple web sites to a central location. The project includes a web site to view and search through the errors.
ELMAH, by default, is set up to figure out under which application it is running and will filter the displayed errors based on that application. So, as for your question 1, no, you won't be able to call the .axd from an app and see the errors for all apps. At least not without some extra work. See also this related question.
As for question 2, the default viewer is not designed to be "customized". By that, I mean there aren't any markup parameters you can give it to change the columns it displays. ELMAH itself is open source, though, so you can easily download the source and build a customized version. I would start by having a look at ErrorLogPage.cs, which is the class that "Renders an HTML page displaying a page of errors from the error log."
I've just started developing silverlight applications. I've created a webserivce in my asp.net project. Now, when I try to connect to it through my silverlight project I receive the following error:
"the opreation is not supported for a relative uri"
I am using the following url -->
http://192.168.1.2/MyWebsite/SubVersionedHistory.svc
I can find the class and its methods, but I receive this horrific error when I add it.
Thank you for your help and advice,
Vondiplo
I don't think you're alone in hitting this problem. I hit it today with VS2008SP1 + SL2 trying to create a Service Reference for an ADO.NET Data Service. First time I've hit the error.
Others have detailed similar experiences to reach this error:
http://silverlight.net/forums/t/87535.aspx
http://silverlight.net/forums/t/56629.aspx
It's not entirely clear at this point if the issue is with the IDE "Add Service Reference" dialog or something specific in the services causing this error. In my case, however, my code still worked despite the error message. I simply passed the URL to my service in the constructor of my DataService proxy client, like this:
var context = new DataServiceContext(new Uri("NorthwindDataService.svc", UriKind.Relative));
Summary point: Just because you hit this error in the IDE, your service reference may still work. Give it a try and let us know if you're seeing errors at run time.
Hope that helps.
[UPDATE] Based on some other advice I've found and tested, you can also try:
deleting your Service Reference
deleting your ServiceReferences.ClientConfig file
saving your solution
and then closing and reopening it in VS.
The simple act of closing and reopening your project has been shown to fix several problems with the Add Service wizard. Re-run the Add Service Ref wizard and you may have better luck. I personally tested this solution on a project today and can confirm it works. Hope that adds extra help to finding your solution.
You should be more specific about your problem. For example, are you having this problem when adding the reference or when you actually try to consume the service?
It sounds like you need to be using a full path, including the "http://" but that is just a shot in the dark based on the error message you provide.
[edit]If you are using the built in ASP.NET server instead of IIS then be sure you set a specific port number and use it in your path. For example, I have used http://localhost:4940/MyService.svc for testing[/edit]
Maybe this response can help you
You cannot use AbsolutePath, You need to use AbsoluteURL. Build your URL this way:
Uri url = new Uri(App.Current.Host.Source, "../settings.xml");client.DownloadStringAsync(url);
http://silverlight.net/forums/p/28912/95541.aspx
HTH
Braulio
Check the ServiceReferences.ClientConfig
if there are multiple endpoints there you will get this exception. one thing that can cause this is referencing a service using casini, later switiching to IIS express and rereferencing the service.