How to enable Trace Logging in a VB web project - asp.net

I'm currently developing a web project in VB.net.
I have run into some errors experienced more in IE11 than any other browser. I have researched all options related to turning the project cookieless, changed my variables and such around, and tried to make the project as sound as possible for all browsers, but to no avail.
My next step is to enable Trace Logging for the site so that I may ascertain the identity of the error.
The error I am getting is thus:
As I've siad, I've looked into the dropdownlist that is described in the error. I've changed it. Done everything I could
Thing is, I use the same page (in a sense) on another webpage, and the error does not occur. Similiary, in Chrome, Firefox even IE9 there is no error. Only in IE11.
As I said, I would like to implement Trace Logging. Now I have in my web.config
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="WebPageTraceListener"
type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" initializeData="C:\Diagnostics\trace.svclog"/>
</listeners>
</trace>
I have set the initializeData to the C drive for testing (for me) and because I would like to see if another PC gets the error, hence the log should go to their machine.
My
<customErrors>
is set to off.
Yet there is no file! In my web.config, I had
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" writeToDiagnosticsTrace="true" />
But removed everything expect for
writeToDiagnosticsTrace="true"
But still nothing.
I followed Walkthrough: Integrating ASP.NET Tracing with System.Diagnostics Tracing, specifically the sections on logging through the web.config. I focused on the section titled
Routing All Tracing Output to .NET Framework Tracing
but following this, I thought I would get a file or something. But nothing came.
How do I get the trace file? Am I doing something wrong in the web.config? The user has full access to the folder.
Can this even be done?
I had this in a C# WPF application that logged only critical erros
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" maxMessagesToLog="300" logMessagesAtServiceLevel="true" logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
Can I do the same for a web project?
What more can I do?
Your help is greatly appreciated
EDIT
Apologies for not posting what I'm trying to do.
On page load, the dropdownlist is populated
ddlMedicalAid.DataSource = objMedicalAids
ddlMedicalAid.DataValueField = "MedicalAidID"
ddlMedicalAid.DataTextField = "Name"
ddlMedicalAid.DataBind()
Now when the page is rendered, the values are present, and the selected value in this case would be
Medical Aid 1
When the user enters text and clicks search, the method calls a service, in which the selected medical aid's value and the text is sent. The text has a required validator on it, so there is no way that a null value is passed there. It is for some reason the dropdownlist
Dim objTransactions As ArrayList
objTransactions = Managers.Transaction.GetTransactionsByMedicalAid(ddlMedicalAid.SelectedValue, strMember)

Believe it or not, I just had to change the current .browser file to accommodate the various browsers. This eliminated the main error, working in Chrome, but not in IE11. I just thought getting a tracer would help. Seems this did it
For more help, Browser Definition File Schema (browsers Element)

Related

404 Not Found aspx file but it is there

I´m using Plesk and in Web scripting and statistics I have Microsoft ASP support in ON.
I uploaded a application (which works correctly in my PC) to a directory and it can be shown but when I go to the aspx file it shows me the 404 error (The path is the correct).
I noticed that some files in "shtml" extension are neither shown by the server.
This is my very first time with ASP.NET, ISS8 and Plesk. I don´t know what to do. I will thank you for your help
You have to set the HTTP Handler Extension. If you have no access to IIS directly, you could do on the web.config:
Open the Web.config file for the application, locate the httpHandlers element of the system.web section and add an entry for the file-name extension
Example:
<system.webServer>
<handlers>
<add name="SampleHandler" verb="*"
path="SampleHandler.new"
type="SampleHandler, SampleHandlerAssembly"
resourceType="Unspecified" />
</handlers>
</system.webServer>
For more configuration options please refer to:
https://msdn.microsoft.com/en-us/library/bb515343.aspx
and
https://msdn.microsoft.com/en-us/library/46c5ddfy(v=vs.100).aspx
Check also the Custom Handler Policy of Plesk that should not be enabled:
https://docs.plesk.com/en-US/onyx/administrator-guide/plesk-administration/securing-plesk/custom-handlers-policy.76787/
Here I've found also another interesting document:
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/handlers/
Scroll down and you'll find a piece of code to add the handlers programmatically, even if I suggest you to add them in your web.config

Physical Folder Breaks ASP.NET URL Routing on IIS Express

IIS Express is producing 403.14 Forbidden errors when a URL that would otherwise be handled through ASP.NET URL routing happens to correspond to a physical folder in my ASP.NET project. (The folder contains only code, and it's coincidental that the folder name happens to match the URL of a page; my URL structure is determined dynamically by a database, and users can edit that structure, so although I could just rename my project folder, in general I can't prevent this sort of collision occurring.)
This seems to be happening because the DirectoryListingModule steps in to handle the request, and then promptly fails it because directory browsing is disabled. I've tried removing this:
<system.webServer>
<handlers>
<remove name="StaticFile" />
<add name="StaticFile" path="*" verb="*"
modules="StaticFileModule" resourceType="Either" requireAccess="Read" />
</handlers>
</system.webServer>
That removes the default StaticFile handler configuration, which has modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule", and replaces it with a configuration that provides just the feature I want. (I want static file serving, but I have no need for directory listing or default documents in this app.) But the effect seems to be that IIS then produces a completely empty (0 byte) response (with a 200 status) when I hit the offending page.
So next, I tried configuring the StaticFile handler to handle only the specific physical folders that I want to make available:
<system.webServer>
<handlers>
<remove name="StaticFile" />
<add name="StaticFileCss" path="style/*.css" verb="*"
modules="StaticFileModule" resourceType="Either" requireAccess="Read" />
<add name="StaticFileScripts" path="Scripts/*" verb="*"
modules="StaticFileModule" resourceType="Either" requireAccess="Read" />
</handlers>
</system.webServer>
But when I hit the offending URL, this then produces a 404.4 - Not found error, with a message of The resource you are looking for does not have a handler associated with it.. (The Detailed Error Information on the error page says that we're in the IIS Web Core module, during the MapRequestHandler notification, the handler is Not yet determined, and there's an Error Code of 0x80070002, which is a COM HRESULT that corresponds to the Win32 ERROR_FILE_NOT_FOUND error.)
The mystifying thing is that it's not even bothering to ask ASP.NET whether it has a handler for it. IIS seems to be deciding all by itself that there definitely isn't a handler.
This only happens when there's a folder that matches the URL. All other resources with dynamically-determined URLs work just fine - IIS asks ASP.NET for a handler, ASP.NET's routing mechanism runs as normal, and if the URL corresponds to one of my dynamically defined pages, it all works fine. It's just the presence of a physical folder that stops this all from working.
I can see it's IIS doing this because I get one of the IIS-style error pages for this 404, and they have a distinctive design that's very different from the 404s produced by ASP.NET. (If I try to navigate to a URL that neither corresponds to a physical folder, nor to a dynamic resource, I get a 404 page generated by ASP.NET. So normally, IIS is definitely handing requests over to ASP.NET, but IIS is definitely getting in the way for these problematic resources.)
I tried adding this inside my <system.WebServer>, in case the problem was that IIS has decided that requests corresponding to physical folders do not meet the managedHandler precondition:
<modules runAllManagedModulesForAllRequests="true">
But that doesn't appear to help - it still doesn't get ASP.NET routing involved for URLs that correspond to physical folders. In any case, it would be suboptimal - I would prefer not to have managed handlers run for the content that I definitely want to handle as static content. I effectively want ASP.NET URL routing to be used as a backstop - I only want it to come into play if the URL definitely doesn't refer to static content.
I don't understand why ASP.NET isn't even asking ASP.NET what it thinks in this scenario. Why is it not calling into ASP.NET during the MapRequestHandler phase if there's a physical folder that happens to correspond to the URL?
When a physical file or folder with the same URL as the route is found, routes will not handle the request and the physical file will be served.
Althrough you can change this behavior by setting the RouteExistingFiles Property from the RouteCollection object to true.
Take a look at the MSDN page Scenarios when routing is not applied

Can I set up Windows Authentication in WebMatrix Beta 2?

I have an ASP.NET site where authentication mode="Windows". Just downloaded WebMatrix beta 2 yesterday, trying to debug my app.
In WebMatrix, I'm getting 401 errors after pressing F5 in Visual Studio. Also in VS, getting "Unable to start debugging on the web server. An authentication error occurred while communication with the web server." When I click the help button, MSDN tells me I need to enable Windows authentication.
I don't see an option for authentication in WebMatrix. This question is similar, but doesn't seem to apply for me (and no answer).
More info (not sure if this applies). I've enabled SSL in WebMatrix. VS is set up to use a custom web server with the URL of https://localhost:44300/routing/development.aspx. In WebMatrix, the URL in the request view is https://localhost:44300/routing/development.aspx/debugattach.aspx (not sure where debugattach.aspx is coming from).
I think I found the answer. Looks like Beta 2 (I haven't used Beta 1) has a lot of options that are not accessible via the UI.
In %My Documents%\IISExpress\config\applicationhost.config, at line 349 is
<windowsAuthentication enabled="false">
Changing "false" to "true" works for me.
Just got this working today. You'll have to edit the server's applicationhost.config file manually since there isn't any UI to it. This is located under your my documents/IISExpress/config/applicationhost.config.
Once you have this open in your favorite text editor, near the bottom you'll have to add a section of XML to setup your site to run with custom settings. The line above the </configuration> terminator, copy and past the following into your file:
<location path="SiteName">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<basicAuthentication enabled="true" />
<windowsAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
</location>
Make sure you change path="SiteName" to have it match the website's name in WebMatrix. Also make sure you change anonymous, basic, or windows auth to true or false depending on what you need your website to run as.
I have the same issue and am also looking for a solution.
Frankly saying, I wouldn't even imagine that this should work (especially after seeing Scott Guthrie link to article that tells to use macros for attaching to iisexpress process: http://www.intrepidstudios.com/blog/2010/7/11/debug-your-net-web-project-with-iis-express-t.aspx), but this used to work properly for me in Beta 1. So, one solution for you could be to go back to Beta 1.
try
<appSettings>
<add key="enableSimpleMembership" value="false" />
</appSettings>

Why isn't my IHttpHandler being called?

I'm trying to get a custom handler to work for a specific URL (or set of URLs) in ASP.NET 3.5.
The handler doesn't actually do anything significant yet - it just logs the request. I can post the code if anyone things it's relevant, but I really don't think it's being called at all. (In particular, for normal exceptions I get a custom error page and logging... here I'm just getting the vanilla IIS 404.)
Here's the relevant bit of the web.config file:
<system.web>
<httpHandlers>
<add verb="GET,POST" path="*.robot" validate="false"
type="CSharpInDepth.Wave.RobotHandler, CSharpInDepth"/>
</httpHandlers>
</system.web>
(Obviously there's other stuff in that section too, but I don't think it's relevant.)
Locally, running under the dev server, it works fine. On my real box, I always get a 404. Everything under the web site directory itself is the same (replicated via svn). That includes the bin directory containing CSharpInDepth.dll, which I've verified contains CSharpInDepth.Wave.RobotHandler.
I try to fetch http://csharpindepth.com/foo.robot and just get a 404.
I've tried with and without the assembly name, specific URLs or wildcarded ones... nothing's working.
I'm sure I've just missed some simple flag somewhere in the IIS configuration, but I'm blowed if I can find it...
EDIT: It's IIS version 6. Attempting to add *.robot to the ISAPI filter now...
Well if the hosting box is IIS7 in integrated pipeline you need to add it into the other bit of the config:
<system.webmodules>
....
<modules>
<add name="RobotHandler" type="CSharpInDepth.Wave.RobotHandler, CSharpInDepth"/>
</modules>
....
</system.webmodules>
If it's IIS6 then you'll need to map *.robots to the ASP.NET ISAPI DLL.
(For the non-Skeets you do this as follows)
Open up IIS admin.
Right click on
the Web site you want to configure
and select Properties form the
context menu. This will display the
Web Site Properties dialog.
Select
the Home Directory tab and click the
Configuration button. This will
display the Application
Configuration dialog box.
Click
Add.
Select the aspnet_isapi.dll
from the .NET framework directory,
the extension you want mapped and
either All Verbs, or just the ones
you want to map.
Click ok.
Jon,
You'll have to configure the IIS script mappings to pass *.robot to aspnet_isapi.dll.

CustomErrors mode="Off"

I get an error everytime I upload my webapp to the provider. Because of the customErrors mode, all I see is the default "Runtime error" message, instructing me to turn off customErrors to view more about the error.
Exasperated, I've set my web.config to look like this:
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
And still, all I get is the stupid remote errors page with no useful info on it.
What else can I do to turn customErrors OFF ?!
This has been driving me insane for the past few days and couldn't get around it but have finally figured it out:
In my machine.config file I had an entry under <system.web>:
<deployment retail="true" />
This seems to override any other customError settings that you have specified in a web.config file, so setting the above entry to:
<deployment retail="false" />
now means that I can once again see the detailed error messages that I need to.
The machine.config is located at
32-bit
%windir%\Microsoft.NET\Framework\[version]\config\machine.config
64-bit
%windir%\Microsoft.NET\Framework64\[version]\config\machine.config
"Off" is case-sensitive.
Check if the "O" is in uppercase in your web.config file, I've suffered that a few times (as simple as it sounds)
In the interests of adding more situations to this question (because this is where I looked because I was having the exact same problem), here's my answer:
In my case, I cut/pasted the text from the generic error saying in effect if you want to see what's wrong, put
<system.web>
<customErrors mode="Off"/>
</system.web>
So this should have fixed it, but of course not! My problem was that there was a <system.web> node several lines above (before a compilation and authentication node), and a closing tag </system.web> a few lines below that. Once I corrected this, OK, problem solved. What I should have done is copy/pasted only this line:
<customErrors mode="Off"/>
This is from the annals of Stupid Things I Keep Doing Over and Over Again, in the chapter entitled "Copy and Paste Your Way to Destruction".
For Sharepoint 2010 applications, you should also edit C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\web.config and define <customErrors mode="Off" />
I tried most of the stuff described here. I was using VWD and the default web.config file contained:
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
I changed mode="RemoteOnly" to mode="Off". Still no joy.
I then used IIS manager, properties, ASP.Net Tab, Edit configuration, then chose the CustomeErrors tab. This still showed RemoteOnly. I changed this to Off and finally I could see the detailed error messages.
When I inspected the web.config I saw that there were two CustomErrors nodes in the system.web; and I have just noticed that the second entry (the one I was changing was inside a comment). So try not to use notepad to inspect web.config on a remote server.
However, if you use the IIS edit configuration stuff it will complain about errors in the web.config. Then you can rule out all of the answers that say "is there an XML syntax error in your web.config"
The one answer that actually worked to fix this I found here: https://stackoverflow.com/a/18938991/550975
Just add this to your web.config:
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough"/>
</system.webServer>
<configuration>
You can generally find more information regarding the error in the Event Viewer, if you have access to it. Your provider may also have prevented custom errors from being displayed at all, by either overriding it in their machine.config, or setting the retail attribute to true (http://msdn.microsoft.com/en-us/library/ms228298(VS.80).aspx).
My problem was that i had this defined in my web.config
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" />
<error statusCode="500" responseMode="ExecuteURL" path="/Error/Internal" />
</httpErrors>
I also had this problem, but when using Apache and mod_mono. For anyone else in that situation, you need to restart Apache after changing web.config to force the new version to be read.
If you're still getting that page, it's likely that it's blowing up before getting past the Web.Config
Make sure that ASP.Net has permissions it needs to things like the .Net Framework folders, the IIS Metabase, etc. Do you have any way of checking that ASP.Net is installed correctly and associated in IIS correctly?
Edit: After Greg's comment it occured to me I assumed that what you posted was your entire very minimal web.config, is there more to it? If so can you post the entire web.config?
Actually, what I figured out while hosting my web app is the the code you developed on your local Machine is of higher version than the hosting company offers you. If you have admin privileges you may be able to change the Microsoft ASP.NET version support under web hosting setting
We had this issue and it was due to the IIS user not having access to the machine config on the web server.
We also ran into this error and in our case it was because the application pool user did not have permissions to the web.config file anymore. The reason it lost its permissions (everything was fine before) was because we had a backup of the site in a rar file and I dragged a backup version of the web.config from the rar into the site. This seems to have removed all permissions to the web.config file except for me, the logged on user.
It took us a while to figure this out because I repeatedly checked permissions on the folder level, but never on the file level.
I had the same issue but found resolve in a different way.
-
What I did was, I opened Advanced Settings for the Application Pool in IIS Manager.
There I set Enable 32-Bit Applications to True.
Try restarting the application (creating an app_offline.htm than deleting it will do) and if you still get the same error message, make sure you've only declared customErrors once in the web.config, or anything like that. Errors in the web.config can have some weird impact on the application.
Do you have any special character like æøå in your web.config? If so make sure that the encoding is set to utf-8.
Is this web app set below any other apps in a website's directory tree? Check any parent web.config files for other settings, if any. Also, make your your directory is set as an application directory in IIS.
If you're using the MVC preview 4, you could be experiencing this because you're using the HandleErrorAttribute. The behavior changed in 5 so that it doesn't handle exceptions if you turn off custom errors.
You can also try bringing up the website in a browser on the server machine. I don't do a lot of ASP.NET development, but I remember the custom errors thing has a setting for only displaying full error text on the server, as a security measure.
I have just dealt with similar issue. In my case the default site asp.net version was 1.1 while i was trying to start up a 2.0 web app. The error was pretty trivial, but it was not immediately clear why the custom errors would not go away, and runtime never wrote to event log. Obvious fix was to match the version in Asp.Net tab of IIS.
Also make sure you're editing web.config and not website.config, as I was doing.
I have had the same problem, and the cause was that IIS was running ASP.NET 1.1, and the site required .NET 2.0.
The error message did nothing but throw me off track for several hours.
Make sure you add
right after the system.web
I put it toward the end of the node and didn't work.
If you are doing a config transform, you may also need to remove the following line from the relevant web.config file.
<compilation xdt:Transform="RemoveAttributes(debug)" />
Having tried all the answers here, it turned out that my Application_Error method had this:
Server.ClearError();
Response.Redirect("/Home/Error");
Removing these lines and setting fixed the problem. (The client still got redirected to the error page with customErrors="On").
I have had the same problem, and I went through the Event viewer application log where it clearly mention due to which exception this is happened. In my case exception was as below...
Exception information :
Exception type: HttpException
Exception message: The target principal name is incorrect. Cannot generate SSPI context.
at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app)
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)
The target principal name is incorrect. Cannot generate SSPI context.
I have just updated my password in application pool and it works for me.
It's also possible in some cases that web.config is not formatted correctly. In that case you have to go through it line by line before will work. Often, rewrite rules are the culprit here.
That's really strange. I got this error and after rebooting of my server it disappeared.
For me it was an error higher up in the web.config above the system.web.
the file blah didn't exist so it was throwing an error at that point. Because it hadn't yet got to the System.Web section yet it was using the server default setting for CUstomErrors (On)
None of those above solutions work for me. my case is
i have this in my web.config
<log4net debug="true">
either remove all those or go and read errors logs in your application folder\logs
eg.. C:\Users\YourName\source\repos\YourProjectFolder\logs

Resources