I am developping a web application by using the ASP .NET MVC 3 framework.
I have implemented an ASPX ViewPage containing a CrystalReportViewer control.
I have got help by looking at the project downloadable at : http://hasibulhaque.com/?p=244

Here is the action sequence to load my ASPX ViewPage :

  1. An action method of a controller is called.
  2. A redirection to the ASPX ViewPage is made.

My ASPX ViewPage is in a folder named AspNetForms.
The folder AspNetForms is under the root of my project.

I have made a test.
I have moved the AspNetForms folder under the Views folder.
Then I have updated the redirection written in the action method.
But then I have faced a 404 HTTP error when I have tried to load my ASPX ViewPage.

Does someone can explain to me what is so special about the Views folder ?

I am not sure whether the routing has something to do with my HTTP error.
For information here is my RegisterRoutes method as written in the Global.asax.cs file :

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

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
         // Default parameters
        new { controller = "Accueil", action = "Accueil", id = UrlParameter.Optional }
    );
}
有帮助吗?

解决方案

The View folder contains a web.config file with the following lines:

 <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
 </handlers>

This special handler blocks all access to the Views folder. If you remove those lines you will be able to access your ASPX page. These lines are their for security reasons. If you remove them all your razor views can also be viewed directly.

其他提示

You don't mention anything about your controller.

In MVC, all web requests (well, almost all) go through a controller. If you have not defined a controller action, it will give you a 404. That's pretty basic MVC, and if you don't understand this you really need to go back to the tutorials.

A view is never rendered directly to the client. If you are trying to send a standard .aspx page with code behind, then this is not a view. It's a webform. MVC disallows access to the Views folder directly via URL because Views can contain sensitive information. If you want a file that is accessed directly, it must be placed outside the Views folder.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top