ASP.NET-MVC How to serve static content?
Basically I want to have a static website, but I did this and an ASP.NET-MVC application to serve a simple HTTP mail request to save something to the database. Sometimes in the future a view may be implemented, but not at this time. What I found is some strange behavior that I cannot explain why?
Site structure:
Root/ index.html test.html img/ image.png test.html
The server is hosted on an IIS 8.9 server.
Route configuration and controller:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "ApiPostData",
url: "api/{action}",
defaults: new { controller = "Api" }
);
}
public class ApiController : Controller
{
[HttpPost]
public JsonResult PostSomeData(SomeData someData)
{
// save to database
return Json(true);
}
}
But it behaves completely wrong and unpredictable: In the examples:
www.mysite.com -> displays index.html OK
www.mysite.com/index.html -> error 500
www.mysite.com/img/image.png -> shwon image which is ok
www.mysite.com/img/test.html -> error 500
www.mysite.com/api/postsomedata -> calls the controller method as it should
This is completely illogical. Why does the server make a distinction between static context. I need an explanation of this behavior and a way to get IIS to serve static content.
source to share
No one has answered this question yet
Check out similar questions: