Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 01, 2013 10:22 PM by kevinbky
Jul 01, 2012 01:47 AM|LINK
I'm trying to build a Web API project using Visual Basic on Webforms.
I've noticed that in the global.asax file, RouteTable.Routes.MapHttpRoute is an option which is only available in the C# version of global.asax. When creating a VB version of the file, only .MapPageRoute
Is HTTP routing only available in a C# project, or is there another way to call this class?
Jul 01, 2012 08:09 AM|LINK
MapHttpRoute is an extension method on RouteCollection, defined in the System.Web.Http namespace. You need an Imports statement (in Global.asax or in the config file) to bring this namespace in scope. My guess is that your C# project has it while your VB
version doesn't. Add the following to your Global.asax and MapHttpRoute will light up:
Hope this helps,
Jul 01, 2012 09:24 AM|LINK
I've already imported System.Web.Routing and System.Web.Http. Still don't have MapHttpRoute as an option.
Jul 01, 2012 09:43 AM|LINK
That's odd. Does your project have a reference to the Sysrtem.Web.Http assembly? Can you compare the differences in references between the VB and C# projects?
I just tested this in VS 2012 and it works fine for VB....
Jul 02, 2012 07:39 AM|LINK
I'm running Visual Web Developer 2010. It is weird that MapHttpRoute only shows up in a C# version of global.asax. I note that it's written as "(extension)" and I've read that MapHttpRoute is part of HttpRouteCollectionExtensions. Maybe this extension
wasn't written to be available for use in VB?
Jul 02, 2012 01:12 PM|LINK
Extension methods are a framework feature, and as such are usable by C# as well as VB, as long as you reference the assembly that defines them and import their namespace.
Can you describe how you're creating your project? I just did this:
1. Started Visual Studio 2010
2. Choose new MVC 4 application
3. Chose Web API as the template and VB as the language
4. Opened up Global.asax which contains referencs to MapHttpRoute that all compile fine.
One thing that just struck me: is your IntelliSense displaying the Common or All list? MapHttpRoute only apears in the latter. You can switch between the two at the bottom of the IntelliSense list.
Jul 04, 2012 05:59 AM|LINK
Make sure you are referencing System.Web.Http.Webhost in the project, and that you are importing System.Web.Http and System.Web.Routing.
Without referencing System.Web.Http.Webhost the project won't find the extensionmethod MapHttpRoute on the System.Web.Http assembly.
I'm not sure why this is but it solved the problem for me.
Aug 07, 2012 04:35 AM|LINK
This is totally mess up to implement this in to VB.net. I have given reference and import libraries correctly.
At the moment I’m working on VS2010.
Edit : actually i'm working on a VB Asp.net Web Site
Aug 15, 2012 03:51 AM|LINK
I've faced smae issue, and .... will .... it's kind of annoying thing ... but got you the solution...
Actully it seems intellisence crash only... :)
the method MapHttpRoute is availble in VB.NET assembly , but for some reason , Vs 2010 Intellisence wont detect it .... So just Give it a try
type it manually and VS will not raise you any errors or warnings.... and it will work ... or just copy it from here
RouteTable.Routes.MapHttpRoute("Your Api Name as string", "Your RouteTemplate as string" , RouteParameter option)
and everything will be O.K.
I tried it my self... working !!!
May 01, 2013 10:22 PM|LINK
another good reason to user c# :)