c# - ASP MVC 5 and Web Api 2 can't view page on complete links -
i have 2 controllers, 1 mvc , 1 web api 2. latter seems work correctly, first can't display html pages when write full address.
this simple routeconfig.cs
routes.maproute( name: "default", url: "{controller}/{action}", defaults: new { controller = "base", action = "main" } ); )
let's take default example, controller base
, action main
, code straightforward
public actionresult main() { return view(); }
http://localhost/miapps --> work , display content of /view/base/main http://localhost/miapps/base --> work , display content of /view/base/main http://localhost/miapps/base/main --> doesn't work, error is
{"message":"no http resource found matches request uri 'http://localhost/miapps/base/main'.","messagedetail":"no type found matches controller named 'base'."}
i post webapiconfig.cs
, maybe there interaction?
config.maphttpattributeroutes(); config.formatters.jsonformatter.supportedmediatypes.add(new mediatypeheadervalue("text/html")); config.routes.maphttproute( name: "defaultapi", routetemplate: "{controller}/{action}", defaults: new { //id = routeparameter.optional } ); }
the route api controllers should have prefix (usually '/api/') in order make distinction ordinary controllers.
try updating webapiconfig.cs
this:
config.maphttpattributeroutes(); config.formatters.jsonformatter.supportedmediatypes.add(new mediatypeheadervalue("text/html")); config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{action}", defaults: new { //id = routeparameter.optional } ); }
Comments
Post a Comment