System.Web.HttpException: File does not exist

November 20, 2011

If IIS does not find a requested file, ASP.Net throws an exception of type System.Web.HttpException. This exception can be handled in the global.asax Application_Error event handler (see MSDN sample and blog).

There is a difference between requests handled by managed code and static files:

For managed requests, the exception message is

The file /path/to/file.aspx does not exist.

Die Datei /pfad/zu/datei.aspx ist nicht vorhanden.

and the stack trace looks like this:

System.Web.HttpException:
at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)    
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)    
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)    
at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)    
at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)    
at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)    
at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)    
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)    
at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()    
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

For static files, the file name is not included in the exception message

File does not exist.

Datei ist nicht vorhanden.

and the stack trace shows that only the existence of the physical file is checked:

System.Web.HttpException:
at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)    
at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context)    
at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)    
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()    
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

You can still get the requested file by evaluating the Request.Url or Request.Path properties of the current HttpContext.


Finding all Namespaces in a C# Project or Solution

November 17, 2011

To get an overview on which namespaces are declared in a (known or unknown) C# project or solution, you can simple run your favorite grep tool on your source directories:

grep -r "^namespace " *  --include=*.cs --exclude-dir=*Test*
    --exclude=*designer.cs > files-namespaces.txt

Here, the -r switch causes recursive search through all subdirectories, –include names the files to search, –exclude-dir and –exclude the directories and files to exclude from the search. The result is written to a file.

This will produce a list of all namespace declarations.

Using the uniq command of the cmd.net command line utilities we can find all unique namespaces:

grep -r "^namespace " *  --include=*.cs --exclude-dir=*Test*
    --exclude=*designer.cs -h | sort
    | uniq > namespaces.txt

Removing Unused References in Visual Studio 2010

November 16, 2011

The C# IDE lets you easily clean up your .cs files’ using sections by right-clicking in the editor and selecting “Remove and Sort Usings”. Unfortunately, there is no such command for removing unnecessary assembly references from a project.

Searching SO brought up some answers regarding free tools implementing this operation, and the Visual Studio Gallery website contains at least 3 VS Extensions that provide this functionality:

Judging from the reviews pages of each product, all of them seem to share the problem that sometimes they remove assemblies even though they are required for compilation.

(This problem may occur if code in assembly 1 calls assembly 2 which returns an object defined in assembly 3, but assembly 3 is not referenced by assembly 1.)

Reference Assistant has a preview of the remove operation (screenshot), but I am not sure about the other products.

What is your preferred tool for this operation?


300.000 Views, and some Spam

November 11, 2011

This blog as recently passed the 300.000 views mark, and I want to thank the regular and not-so-regular readers for visiting.

I noticed a slight increase in views recently, which is probably due to Google tweaking their search results, but who knows.

I also want to thank WordPress and Akismet for saving me from the deluge of spam comments throughout the years. The Akismet stats say that some 62.000 spam comments have been filtered, the majority of them in this year alone!

For some time I also ran a forum, but I had to close it again because it was mainly visited by spam bots, and the software did not provide effective mechanisms to prevent them from posting.

Most of the recent link spam is in the form

[...] (post title) « devioblog[...]…

so it’s fairly easy to detect. I also figure that huge amounts of comments from the same IP range on a large number of blogs is an obvious indicator of spam.

Some bots still pretend to be human, and congratulate me for my style, content or design

Did you design the design this well with the default design tools? Your design is incredible

We loved your website so much

Yes, thank you too. And some texts are simply meant to make it through the language filter

Thank you a lot for providing individuals with remarkably splendid possiblity to read in detail from this blog. It is often so excellent and jam-packed with a good time for me personally and my office fellow workers to visit your site nearly 3 times in a week to see the fresh items you have got. And indeed, I am always contented with the tremendous principles you serve. Selected 1 facts in this posting are ultimately the most effective we’ve had.

I loved as much as you will receive carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get got an shakiness over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly a lot often inside case you shield this hike.

In the last couple of days spam related to Windows and Office product keys and key generators made me wonder whether Microsoft and other software vendors also maintain blogs here or elsewhere, and use the IP address and URLs provided in the spam comments to identify the spammers?


Generate QR Codes for current URL in Browser

November 8, 2011

I just read this article on Android software and noticed the QR codes for each product mentioned.

Using the i-nigma barcode scanner, my mobile navigated to the product’s Market links.

But how can you easily transfer a URL from your desktop browser to your mobile phone?

One possibility is browser add-ons:

If you cannot or don’t want to install extensions in your browser, you can also paste your URL into SplashURL.net or use their bookmarklets.


Follow

Get every new post delivered to your Inbox.