Am I correct when I say, Web API can run on OWIN and MVC 5 cannot?
So in my project i still need my Global.asax with public class WebApiApplication : System.Web.HttpApplication
At the moment I have my owin Startup.cs which looks like this:
public void Configuration(IAppBuilder app)
{
var httpConfig = new HttpConfiguration
{
};
WebApiConfig.Register(httpConfig);
app.UseWebApi(httpConfig);
app.UseCors(CorsOptions.AllowAll);
RouteConfig.RegisterRoutes(RouteTable.Routes);//MVC Routing
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Is RouteConfig.RegisterRoutes(RouteTable.Routes) nough?
Whenever I browse to any MVC route I get a 404.
Open Web Interface for . NET (OWIN) defines an abstraction between . NET web servers and web applications. OWIN decouples the web application from the server, which makes OWIN ideal for self-hosting a web application in your own process, outside of IIS.
ASP.NET Core: Supports the Open Web Interface for . NET (OWIN).
Owin is the under the hood interface between web servers and web applications. If you only write web applications in a single framework (such as ASP.NET MVC) an only run on one server platform (Windows with IIS) you can ignore Owin.
Yes, you're right, MVC 5 (based in ASP.NET 4) requires IIS, it can't self-host. MVC 6 (based in ASP.NET 5, now called ASP.NET Core 1) doesn't have this limitation. If you need self-hosting, start playing with ASP.NET Core 1 (it is incredibly awesome) or if you need RTM right now, use WebAPI.
Am I correct when I say, Web API can run on OWIN and MVC 5 cannot?
Not clear what you're asking but OWIN is not server but it's a middleware which help injecting pipelines in order to pre-process requests in stages and it doesn't depend on WebAPI or MVC version but it depends if hosting server have OWIN specifications implemented.
Is RouteConfig.RegisterRoutes(RouteTable.Routes) enough?
yes this will work for Asp.net MVC but for web api you need to register the routes in separate configuration class. Usually the WebAPI configuration may look like as specified in default Asp.net WebAPI template(> vs2013)
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Make sure the Url you're requesting matches either the MVC or WebAPI route templates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With