PermaLink VS.Net's secret file/URL accesses and custom HttpHandlers04/28/2005 02:38 PM
Here's a case of Microsoft Visual Studio 2003's developers trying to make it too easy for their users.  If you have a web project, VS.Net 2003 tries to make sure that the filesystem you put your web project code in correctly maps to the URL that you are trying to run it from.  It does this by writing some special temp files and then checking that it can access them from the web project's URL.

That might be an ok way to do this, but it breaks when you write your own custom HttpHandler for URL rewriting.  What's worse, you get a cryptic error of "500 Internal Server Error".
First of all, if you're going to be mucking w/ URLs and reading from a web server, you should provide some way of letting your user get the full message so they can get more details to guess what the problem is.  A simple Details button to show the resulting HTML from the web server in VS.Net would have been sufficient.  Then you can hide details for the average user.

Secondly, there should be official documentation on what temporary files VS.Net uses to do this.  Searching for "unable to open web project" and "file path does not correspond to the URL and "The two need to map to the same server location" on Microsoft's web site turned up a single document on how to turn off FrontPage extensions to make this problem go away.  And why does it conflict with FrontPage at all?  Because FrontPage does its own hacks to make sure web projects are in the right directory?  I'd bet there's no doc that tells you what hidden files FrontPage uses


The reason it breaks with your own custom HttpHandler (assuming you handle "system" extensions like .htm) is that you have to tell it to use ASP.Net's handlers for these special temporary files (which you don't know the names of)-:  Here's what you have to add for VS.Net (also beware of the buggy ASP.Net StaticFileHandler issue mentioned in the 2nd blog):


<!-- for VS.Net Web Projects to open -->

<add verb="*" path="get_aspx_ver.aspx" type="System.Web.UI.PageHandlerFactory" />

<add verb="*" path="vs*_tmp.htm" type="System.Web.StaticFileHandler" />


http://blogs.ipona.com/james/archive/2005/02/16.aspx
http://dotnetguy.techieswithcats.com/archives/003114.shtml

And here are a few other links in case you have to go through the pain of writing an HttpHandler (J2EE Servlet Filters are sooooo much less painful):


http://www.developerfusion.com/show/4643/2/
http://scottonwriting.net/sowBlog/posts/943.aspx
http://www.benmiller.net/blog/
http://weblogs.asp.net/rmclaws/archive/2004/02/03/66689.aspx

If your web site has web services, you also have to add an exclusion for .asmx files like so:
  <add verb="*" path="*.asmx"
    type="System.Web.Services.Protocols.WebServiceHandlerFactory,
    System.Web.Services, Version=1.0.5000.0, Culture=neutral,
    PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
You may have other "system" extensions that you have to let .Net built-in classes handle.  You should peruse the machine.config on your system to see if you have any others that might be of interest to your web application.

Comments :v

1. rajendra10/10/2008 10:29:03


i worked on the url mapping in global.aspx file the things are working properly offline but when i tried to do this online it is not working properly...
in offlline i wans giving the url like localhost/go/1001
in online the sme thing is there but not working ....
can anyone give me the solution

rajendra




2. Ronald07/03/2007 13:15:12
Homepage: http://www.booden.net


The solution suggested here didn't work for me, but it made the problem clear to me, so thanks for that.

I have simulated the problem using the debugger, and copied the _tmp.htm file generated bij Visual Studio. Used ieHTTPHeaders to view http header info. Renamed a copy of the _tmp.htm file to .html and looked at the contents. It seemed that these files returned different content. The .html file looked the same as the original file, while the .htm file looked different in the browser than the original file. It seemed that the encoding was different, .Net and IIS handle this differently.

Trying some different approaches I found that adding some code to the custom handler for .htm could eliminate the problem. Here is the part of the code that fixed the problem for me:

context.Response.ContentEncoding = Encoding.GetEncoding(0); //use regional setting ANSI (prevents the problem)
context.Response.WriteFile(url);

So, if you check for _tmp.htm files, and handle them using the above code, your Visual Studio 2003 will be happy again.
(Don't forget to remove the 'vs*_tmp.htm' handler if you tried it.)

Hopefully this will help others, stumbling on the same problem. This solution made me much happier than removing the .htm extension in IIS and adding it back every time.

(I have used Visual Studio 2003 with SP1.)




3. techieman06/07/2006 10:26:22


I hv added following piece of code to my web.config:

<httpHandlers>
<add verb="*" path="*.htm" type="System.Web.StaticFileHandler" />
</httpHandlers>

But still I m getting error of "Page can not be found". Can n e one please help me ASAP.




4. jedatu05/26/2006 16:12:14


Wow! I have been struggling off and on with this for probably 2 years. At times I have had this error because of Visual Studio's cached files, but one particular project I have, has always been difficult! It would work sometimes and then suddenly stop.

I would recreate the project from scratch and it would work fine. Then I would close and reopen it only to have it fail. I knew about the files going back and forth and I had seen other posts about setting permissions and setting mime types and more. Like you mentioned the documentation here are thin and the error messages are useless.

Guess what. I was mapping the .htm extension to the ASPNET_ISAPI.DLL. Based on this post, I tried adding the httpHandlers to the config, but that didn't work. Maybe they need to be in the correct sequence. For now, I have resorted to removing the .htm extension mapping in IIS before opening the project, then re-adding it. A slight inconvenience compared to my previous experience.

Thanks for posting this!




5. Yusuf02/12/2006 09:54:16


Hi
I installed sample asp.net applications (vb.net) using the setup that came with a ms press book. I am getting the "The two need to map to the same server location" error. I tried the solution you gave. I added the <add verb.../> nodes under the <configuration/system.web> node, but I still get the same error. Please can someone help me. I searched all over the net but could not find a solution. Please, please some one help me




6. Andrey09/21/2005 20:58:21
Homepage: http://www.ultrazoom.ru


My VS7 started to tell me all of this "unable to open web project" and "file path does not correspond to the URL" and "The two need to map to the same server location" possibly when I have changed Global.asax.cs with changing incoming request page.htm to incoming.RewritePath("default.aspx"+param);
Other projects still working, but this one I can't load ... do u suggest me to kill FPE somehow, but how?




7. Barry09/15/2005 17:58:52


Ditto. Thanks. Saved me many hours.




8. Matthew King05/15/2005 10:37:04


Great Stuff! I've been suffering the pain of manually removing the file mapping on IIS everytime I want to open my web project

Id previously tried everything I could think of to make VS.NET open the project but never worked it out - this has just made life alot easier..

Thanks very much!




Start Pages
RSS News Feed RSS Comments Feed CoComment Integrated
The BlogRoll
Calendar
June 2024
Su
Mo
Tu
We
Th
Fr
Sa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Search
Contact Me
About Ken
Full-stack developer (consultant) working with .Net, Java, Android, Javascript (jQuery, Meteor.js, AngularJS), Lotus Domino