0

I have a funny problem which I cannot explain. I have an ASP.NET-MVC application for sole reason to have a single hhtp endpoint to post some stuff on the server. All other stuff is pure static content.

My structure simplified:

Root/
    index.htm
    img/
        image.png
        test.html

In the root I have my index.html whis is served fine. If I point to www.mysite.com/img/image.png the image is shown as it should be. If I point to www.mysite.com/img/test.html I get 500 error. Why is the html not served from subfolder but image is?

EDIT - UPDATE

Url www.mysite.com displays index.html. Url www.mysite.com/index.html results in 500 error.

I cannot explain this to my self. Does ASP.NET MVC application not serves html files and that www.mysite.com hit index.html because (I guess) this is setup as default in IIS settings?

On this observation the question could be rephrased as: Why is img/image-png served but img/test.html not ?

EDIT UPDATE 2

By popular request I post my route config:

public static void RegisterRoutes(RouteCollection routes)
{
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
             name: "ApiPostData",
             url: "api/{action}",
             defaults: new { controller = "Api" }
        );
}

Besides that single action that return action with JSON rezult, everything elese is simple static web site with static content.

And my controller:

public class ApiController : Controller
{

    [HttpPost]
    public JsonResult PostSomeData(SomeData someData)
    {
            // save to database
            return Json(true);
    }
}
6
  • How are you calling your views from your controller? can you post the code? Commented Jun 3, 2015 at 2:56
  • There are no views. Just one simple action that writes sometginh to db and returns json. This is static content, it should have nothing to do with controllers. Commented Jun 3, 2015 at 3:11
  • Whats server are you using (Casini\IIS Express\IIS) and what version ? If IIS, are you using classic or integrated pipeline? Routing setup ? Commented Jun 3, 2015 at 3:49
  • You'll probably need to, at a minimum, install ELMAH so that you can get a log of the exception(s). You might also benefit from installing Glimpse and stepping through the request. Anything else is pure conjecture at this point. Commented Jun 3, 2015 at 5:58
  • Server is IIS 8.0. I use integrated pipeline. The thing is on the hosting so I have limited option available. Routing setup is very simple. I will ad it above. But In case I do not get something wrong the asp.net-mvc routing should not be invoked for static content. Commented Jun 3, 2015 at 6:23

1 Answer 1

1

Whithout posting the code you are using to render your views from your controller , it's hard to tell what's exactly is the issue. But i am guessing it's a routing problem or not calling the html file correctly.

In order to serve your other test.html you can try this:

public ActionResult Index()
{

    var staticPageToRender = new FilePathResult("~/img/test.html", "text/html");
    return staticPageToRender;
}
Sign up to request clarification or add additional context in comments.

2 Comments

There is no controller in action. Static page, static content.
You may need to look at your server log to find out about the actual error message of "HTTP 500 Internal Server". This error message can mean anything, ranging from incorrect virtual directory permission, wrong path, components are not installed properly, anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.