MVC4 Areas in VB.NET giving 404

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Reaction score
13
So I'm messing around with MVC and getting it modular in a way (by using Areas)

I've found the template for C# and VB.NET differs slightly when it comes to Namespaces, in C# it will work beautifully, but in VB.NET it's more retard than I'd like to admit. A lot of Googling left me with no real answers, only that it has something to do with Namespaces or something left out of the template when creating the project and 99% of the people knowing exactly where to fix it. (because everyone running into this problem is a genius and doesn't care to show code examples of the changes they made for it to work)

But I'm more "F5 till it works smart" than "Ah duhr, this is the inner workings lets trace and write exam papers and manuals smart" (lol)

So here is what I've learned, in your AreaRegistration.vb file you need to specify the Namespace like so:

Code:
context.MapRoute( _
                "TestArea_default", _
               "TestArea/{controller}/{action}/{id}", _
                New With {.controller = "TestAre", .action = "Index", .id = UrlParameter.Optional}, _
                [b]New String() {"TestArea.*"}[/b] _
            )

And that's about it hey. The important part appears to be the ".*"

I had it "MyTest.TestArea" which didn't seem to work at all (tried it a few billion different ways), then saw some random post with ".*" and figured, I'm going to give up anyway, might as well try this bull****. And it worked.

Not sure if this is correct or not, but it produced the result I wanted. Will see once I get further into the project if there's any more issues.
 
Can I ask why you are using vb?

I agree on the c# bit being cleaner. Here's an area in c# for comparison:

public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute("MyArea_default", "MyArea/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional } );
}

Looking at your code, you've had to specify "An enumerable set of namespaces", which is what I haven't had to do in C#. MVC works using reflection, where it iterates through the values in the path, matching them up to the namespace tree in the solution. What's happened here is that MVC didn't know what root namespace to start matching on for the area. You've told it to narrow its search inside the TestArea namespace. It seems that for VB, or at least your solution, MVC was unable to resolve the correct namespace to look in... which is strange as it really could just find the namespace that the AreaRegistration class resides in.
 
Last edited:
http://geekswithblogs.net/cokobware....net-mvc-4-pluggable-application-modules.aspx

^ That's basically what I'm doing. c# works perfectly but VB.NET spazzes out.

Basically it boiled down to the project template when creating it in VS.NET (which, as you pointed out, has to do with Namespaces). That bit is in the AreaRegistration class, and I did change it's namespace to the project I was working in (could be something to do with the "tutorial" I showed)

I'd love to go the c# route, but the company I'm working with currently wants/needs VB.NET based stuff. I'm doing a proof of concept in my spare time and one of the requirements is that multiple developers can work on different modules and/or we can deploy 1 section of the site without redeploying the ENTIRE site (we have several branches that can work offline if lines go down etc, so it's a mission deploying, especially considering how big it is)

I'm only delving into MVC now. So still a huge n00b. But these guys are stuck in iFrames/Reloading/POPUPS (for god sake, they still use POPUPS!!) so I'm trying to breathe in some jQuery/AJAX and new tech into them (and since they have a mandate to upgrade .NET frameworks, I find it might be a perfect opportunity to showcase my ability to adapt/learn/implement/show off cool ****)
 
BTW shogun, do you have any experience in the concept I want to achieve? Basically, if we make a change to a partial view on the project, we don't want to deploy the entire project, only the partial view that changed. With the setup I'm going for, it's going to pack all the views/controllers in 1 DLL, but if I can break it down even further it would be awesome.
 
BTW shogun, do you have any experience in the concept I want to achieve? Basically, if we make a change to a partial view on the project, we don't want to deploy the entire project, only the partial view that changed. With the setup I'm going for, it's going to pack all the views/controllers in 1 DLL, but if I can break it down even further it would be awesome.

If you are looking for modular design you should break it down by component. Not by Partials of that component this will reduce any potential issues you have down the line for misaligned signatures.

Another option is to look at MEF:

http://blog.maartenballiauw.be/post...he-Managed-Extensibility-Framework-(MEF).aspx
http://blogs.msdn.com/b/hammett/archive/2009/04/23/mef-and-asp-net-mvc-sample.aspx
http://mikehadlow.blogspot.com/2010/10/experimental-aspnet-mvc-add-ins.html
http://www.fidelitydesign.net/?p=104
http://blog.longle.net/2012/03/29/building-a-composite-mvc3-application-with-pluggable-areas/

using Ninject Composite injection:

http://blog.longle.net/2012/02/18/building-a-composite-mvc3-application-with-ninject/


Trust issues:
http://shazwazza.com/post/developing-a-plugin-framework-in-aspnet-with-medium-trust


Random:
http://maxtoroq.blogspot.com/2012/06/patterns-for-aspnet-mvc-plugins-routes.html
http://www.squarewidget.com/pluggable-architecture-in-asp.net-mvc-4
http://kennytordeur.blogspot.com/2012/08/mef-in-aspnet-mvc-4-and-webapi.html

Then you will release component sets (sections), because your website will actually just reload the particular dll into the AppDomain.

And for the love of god C# is not difficult to switch from than VB.NET.

Those should point you in the right direction.
 
Last edited:
Yea its not hard switching to c#. Try convincing a company thats almost as old as my dad and set in their VB ways ;)
 
Yea its not hard switching to c#. Try convincing a company thats almost as old as my dad and set in their VB ways ;)

Yeah company i worked for had similar mentality i resigned within 7 months.
 
naw this company is awesome

Yeah any company that doesnt change with the times or at least advance or give their employee's the ability to advance their skill set are **** in my eyes.
 
Well, my skillset is pretty broad as it is already because programming isn't just my job, it's my hobby. I also enjoy jumping into new tech and not stopping till I figure it out. That's why I'm not in bed before 2-3am most nights. Time gets by me.

Your education (or continuance thereof) shouldn't be based on the company you work for. But that's just my opinion.

I'm going into MS CRM/Sharepoint courses in July which should be pretty cool since they use/customize CRM (which is outsourced currently). I've already "weazled" some of my tech in there, but I don't mind dumbing it down into VB.NET

The company does change with the "times". They just don't change their entire base-language everything is written in (as it'll cost them more to do that), just because c# is "trending" (lol). That's why I'm doing the whole MVC4 thing as a proof of concept so we can move into that model and go into .NET 4.5, it's part of my list of things I'm "mandated" to do, and should reflect quite nicely on my bi-annual review coming up (which just so happens to be "pay rise" time)

I'm kind of stuck in the BI/Reporting thing now, which I don't mind, learned a ton, so not trying to rock the boat too much, since we're down 1 dev and busy interviewing
 
Similar here. Was a hobby from 15 or so. Career from 24 and still do it. Purely cause I love to code. Making good dosh from something you love doing is the cherry on the top.
 
Well, my skillset is pretty broad as it is already because programming isn't just my job, it's my hobby. I also enjoy jumping into new tech and not stopping till I figure it out. That's why I'm not in bed before 2-3am most nights. Time gets by me.

Pretty much the same, except im not really into the whole 2-3am stuff anymore did that for many years.

Your education (or continuance thereof) shouldn't be based on the company you work for. But that's just my opinion.

Wrong. The company you work for should push you to further your education/skills the company i work for now enforces at least two MS exams a year.

I'm going into MS CRM/Sharepoint courses in July which should be pretty cool since they use/customize CRM (which is outsourced currently). I've already "weazled" some of my tech in there, but I don't mind dumbing it down into VB.NET
Now sharepoint is a trend and a bad one.

The company does change with the "times". They just don't change their entire base-language everything is written in (as it'll cost them more to do that), just because c# is "trending" (lol). That's why I'm doing the whole MVC4 thing as a proof of concept so we can move into that model and go into .NET 4.5, it's part of my list of things I'm "mandated" to do, and should reflect quite nicely on my bi-annual review coming up (which just so happens to be "pay rise" time)

Not to burst your little world, but if C# was a trend it would have not stuck around for 12+ years. Of which i have been doing it since the .NET 1.1 days. You go and look at the job listings out there and see what is more sought after C# or VB.NET. You tell me which is better ;).

And its not about redoing all their tech in C# its about doing new stuff in it, like you are doing.Also the benefits of moving over to C# are far greater than VB.NET as you will been familiar with the syntax which is pretty much similar to Java while i dislike Java there is no point discrediting its use in the industry i myself am currently using a subset of it for my company(Mine, not one I work for).

I'm kind of stuck in the BI/Reporting thing now, which I don't mind, learned a ton, so not trying to rock the boat too much, since we're down 1 dev and busy interviewing

Why did the Dev leave ? Stagnation?
 
Last edited:
He was fired. came in late constantly, and since I started there till he was fired, didnt complete 1 project (which was simpy a module of our existing intranet site to capture names, apparently he has been working on it for months prior to when I came)

The reason why I said c# is a trend is based off of your opinion on Sharepoint being one lol

I was just joking anyway. I know how the dance works dude. I introduce some juicy c# code that will rock their world, they say no based on the fact that the other dev's can't support it. It will take time, but this company offers me the ability to grow with them quite a bit. Only company I've worked for sonce 2000 that I can see myself retiring at.
 
Top
Sign up to the MyBroadband newsletter
X