0

I'm new in web developing by ASP .Net MVC 4.

I'm creating a view programmatically by creating a file.cshtml while the website is running. While I'm running the code on iis, the created view is not shown and it gives me error that the file is not found and when i rebuild the app it is loaded.

How can I load the file into the iis while running the app ?

  • problem is in IIS settings.. Check AppPool .netframework – Amit Soni Oct 12 '15 at 11:04
  • i would like to know the correct answer for this question. AFAIK, when you run it via localhost, on refresh the actual cshtml file in which you are writing loads up. When hosted in IIS, when you build all the files are sent to some temp folder, so unless you build those files wont go to that temp folder. IIS uses that temp folder to load up the page. – blogbydev Oct 12 '15 at 11:04
  • will this problem still appear when I deploy the website on it's server ? – Ayman Tourk Oct 12 '15 at 11:07

2 Answers2

0

What version of IIS you using ? IIS needs to support running managed modules in order to display your views. Check this post Deploying ASP.Net MVC 4 App on IIS 7

Community
  • 1
  • 1
Abhimanyu
  • 2,173
  • 2
  • 28
  • 44
  • I'm using IIS express .. I wonder if the same problem will appear after deploying the website on server – Ayman Tourk Oct 12 '15 at 11:11
  • It should always run on IIS express. By the way can you pls explain "I'm creating a view programmatically" ?? – Abhimanyu Oct 12 '15 at 12:14
  • creating a file.cshtml while the website is running in the directory that contains all views ex: Home/Views/file.cshtml – Ayman Tourk Oct 12 '15 at 12:38
0

As you say the MVC app is not stopped then rebuilt, right? If so, then the view has not been made "available" for processing by ASP.NET. This means, view has to be discovered (the selected, usu. default, VirtualPathPovider is responsible for this), then the view needs to be compiled (the selected View Engine does this), and only then the view becomes "available" for viewing (pardon the expression).

Once available you can change it many times. No explicit re-compilation is needed.

The overall process is described here (Automatic Compilation section) and here.

If you are curious from where your site is served change the following setting in web.config:

 <system.web>
   ...
   <compilation ... tempDirectory="c:\temp\asp.net" />
   ...
 </system.web>

and you'll see where the compiled files go. So, you have to ensure that the files are copied to the output folder after you dynamically create them. To make things even worse you have to take care of all css, .js, pictures and all other possible contents your view(s) may have.

Alexander Christov
  • 9,625
  • 7
  • 43
  • 58