0

Ive got an aspx file, containing report viewer and im trying to open the file using controller. If i put the file in the root, it works using redirect but if i placed it in the Views folder, it wont open. Appreciate any help and thank you in advanced for your help.

enter image description here

Arif Sam
  • 281
  • 1
  • 8
  • 26

1 Answers1

1

The ~/Views directory has a directory-specific Web.config file that adds a rule that prevents all direct-access to files in that directory tree.

To serve WebForms pages in an MVC project you need to move it to another directory that lacks the Web.config rule (e.g. ~/Content), or disable the rule (not recommended).

Your .aspx file doesn't belong in the ~/Views directory anyway as it is not a View (in the MVC architecture) - it's a "page" :)

Note that your project will not work in ASP.NET Core as support for WebForms has been removed in that version.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • ooo.. so theres no way to place aspx file inside View folder is it? i can only placed it in the root or outside the View folder? – Arif Sam Nov 14 '16 at 03:53
  • @ArifSam Generally, yes. But why is that a problem? You sound disappointed. – Dai Nov 14 '16 at 03:54
  • hahah. Ive just started learning MVC and i thought that i can deliver my report in a purely MVC way to my supervisor. A bit disappointed i suppose. lol – Arif Sam Nov 14 '16 at 03:57
  • another question if you dont mind answering, how do i go back to mvc view from aspx page?
  • @Html.ActionLink("Home", "Index", "Home")
  • using this wont work inside aspx page right? – Arif Sam Nov 15 '16 at 10:59
  • @ArifSam not necessarily. It might still be possible to use URL Routing, but you won't be able to use `UrlHelper`. I don't know how your project (or webserver) is configured so I cannot help you further. – Dai Nov 15 '16 at 11:16
  • which part do you need? Im quite at lost here as not much reference ive found on google. The only question that is the same as mine is this, [link](http://stackoverflow.com/questions/16234423/how-to-open-mvc-4-view-page-from-webform-aspx-page). If you could state the file that you need ill gladly provide it. Thank you so much again for helping. Never thought that a simple button to open another page could be difficult. – Arif Sam Nov 15 '16 at 11:25
  • Fyi, for this project, Ive only created a web application mvc, and add webform on the root. All is left as it is, default configuration, the only thing that i did is add "return Redirect("~/ReportWebForm.aspx")" to Home controller ActionResult to open aspx file. – Arif Sam Nov 15 '16 at 11:41
  • @ArifSam Please post a new StackOverflow question for this separate ASPX-to-MVC linking issue. – Dai Nov 15 '16 at 11:42
  • Done. [New Question](http://stackoverflow.com/questions/40609293/how-to-open-mvc5-view-from-aspx-page) Thanks again. – Arif Sam Nov 15 '16 at 11:58