What is the difference between WebApiConfig.cs and RouteConfig.cs in the App_Start folder of an MVC Web API project in Visual Studio 2012?
The following are the key differences:
RouteConfig.cs is exclusively for configuring ASP.NET routes.
WebApiConfig.cs is for any Web API related configuration, including Web-API-specific routes, Web API services, and other Web API settings.
As cmotley mentions, the ASP.NET web site includes a good listing of what types of configuration can be done in WebApiConfig.cs in this article.
There is no difference as they both accomplish the same thing - adding routes to your route collection. You don't need to use the WebApiConfig class; it's simply a convenient way to organize your code.
If you are familiar with ASP.NET MVC, Web API routing is very similar to MVC routing. The main difference is that Web API uses the HTTP method, not the URI path, to select the action. You can also use MVC-style routing in Web API. This article does not assume any knowledge of ASP.NET MVC.
From Routing in ASP.NET Web API
Related
How to add an ASP.NET MVC project to an existing ASP.NET Web forms application. How to call MVC project page from existing website.
You can refer this step-by-step guide on how to do that.
Your question is similar to
Is it possible to host an asp.net MVC in the same folder as asp.net web forms app?
We were in the exact same situation as you and it's not as bad as you might think. Thanks to Nuget it's a fairly easy process that you can follow and Dave Paquette describes how to do it in his blog post
And once you've got Mvc up and running all you need to do to go from one to the other is to redirect to Mvc from webforms:
Response.Redirect("~/Controller/Action/")
You can also use the Mvc routing system to generate routes from within webforms as well:
System.Web.Mvc.UrlHelper url = new System.Web.Mvc.UrlHelper(HttpContexxt.Current.Request.requestContext)
Response.Redirect(url.Action("Action", "Controller"))
everyone. I've got ServiceStack project and I want to add mvc part(some controllers and views) to it.
I tried just installed MVC and add an area, but it doesn't work.
I tried create new MVC project in the solution, but they work separately.(but I have no ideas how to merge their routes)
Any suggestions?
To use ServiceStack with ASP.NET MVC you need to configure ServiceStack to be hosted on a custom route e.g. /api this way ServiceStack doesn't conflict with ASP.NET MVC Razor handling and you can have ServiceStack handle all Service Routes from /api.
Configure ASP.NET MVC with ServiceStack
Access ServiceStack from MVC
Otherwise you can just use ServiceStack's Razor Support, in which case it can't be used with ASP.NET MVC (as it conflicts and tries to hijack Razor views), so to use ServiceStack Razor start with an empty ASP.NET Project and add the NuGet package:
PM> Install-Package ServiceStack.Razor
and register the RazorFormat plugin, e.g:
Plugins.Add(new RazorFormat());
You can find info about ServiceStack.Razor on razor.servicestack.net
When I create a MVC4 project and choose basic mvc project
I find WebApi related code why this?
Because Microsoft hope that you will use Web API 8-)
http://www.asp.net/web-api
If you don't want to, you can ignore it or even comment it in Global.asax
// WebApiConfig.Register(GlobalConfiguration.Configuration);
i'm using asp.net mvc with vs2008 and IIS7.
What i want to accomplish is that all requests that START WITH 'summer' are routed to the same controller.
'till now i've built tons of routes, but they were all for one path (with parameters offcourse) but this one must route:
www.mysite.com/summercity
www.mysite.com/summermadness
www.mysite.com/summer
www.mysite.com/summerweather
to the same controller.
the only solution i've come up with is 'summer*', but that didn't work :)
Michel
You can use:
/Summer{*Data}
I've only started playing with both ASP.Net MVC and the new-to-VS2008 Dynamic Data Website Templates. I note that they both use routing in their URL handling, and I'm given to understand that because of routing, ASP.Net MVC won't work under IIS6. However my DynamicData site works just fine on IIS6.
I've had to temporarily abandon my exploration of ASP.Net MVC for an upcoming project due to the IIS7 requirement, and I'm wondering what the essential difference between the two is under the hood, i.e. what makes DynamicData sites work on IIS6 and MVC not?
ASP.NET MVC does indeed work under IIS6 (and IIS5 for that matter) as long as you enable wildcard mappings to ASP.NET. I have deployed MVC applications to production using IIS6, so I can guarantree that it's possible.
The key difference is that all URLs in DynamicData end in a file with an ASPX extension so, regardless of physical existance, the ASP.NET runtime is invoked (because ASPX is associated with ASP.NET), whereas most ASP.NET MVC requests to not have an extension (or have an MVC extension, which is not mapped by default) and thus IIS configuration is required before it will work.
IIS7 works automatically because IIS7 itself is managed and thus there is no separation between IIS/ASP.NET.
They all work on IIS6 out-of-the-box, without modifying IIS6. You just have to use some extension that is mapped to asp.net isapi, like .aspx, .ashx or similar.
Also, ASP.NET MVC works on IIS6 without problems! I run it moslty on IIS6, with .html extension mapped to asp.net isapi!
Some shared hosting providers are willing to make changes to IIS6 in order to support extension-less urls. If they don't want to do that, you can ask them to map .html to asp.net, urls are nice with that and seo friendly. Just to mention; google won't mind if you have .aspx or .html, it's the same like without extension.
ASP.Net MVC and Dynamic Data use the same routing engine contained in System.Web.Routing, so they both work under IIS6. The issue is with mapping requests to ASP.Net (as described by #Richard Szalay). MVC will work fine under IIS6 if a wildcard mapping is used, if the .mvc extension is mapped to ASP.Net, or if another file extension already mapped to ASP.Net (.aspx, .ashx, .axd, etc.) is used in your MVC routes.