Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird exception when using IISLocal (works on IISExpression) with ASP.NET MVC

I'm developing an ASP.NET MVC 5 application that use KendoUI . If I run the project under IIS Express everything works fine... if I use IIS Local I got the following exception when I try to load a view

A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll

Additional information: Invalid file name for file monitoring: 'C:\svn\Projects\xxx\trunk\xxx\Views\Shared\EditorTemplates'. Common reasons      for failure include:

- The filename is not a valid Win32 file name.

- The filename is not an absolute path.

- The filename contains wildcard characters.

- The file specified is a directory.

- Access denied.

I've just searched on google and someone suggest to disable under Debug->Exception the throw exception checkbox but if I do so I wouldn't get the view displayed since the output is just javascript...

Anyone has found a solution to this problem? Thanks

like image 434
advapi Avatar asked Nov 09 '22 20:11

advapi


1 Answers

Some things you could try:

Directory Access

Check to ensure your 'C:\svn\Projects\xxx\trunk\xxx\Views\Shared\EditorTemplates' directory is available to the application.

First, determine what user account the IIS application pool assigned to the application.

  1. Open Internet Information Services (IIS) Manager.
  2. Expand the server name.
  3. Expand Sites.
  4. Click the node with the site in question.
  5. Click the Basic Settings... link in the right pane.
  6. Note the name of the application pool in the top right box, and click Cancel.
  7. Click the Application Pools node in the left pane.
  8. Find the application pool with the name from step 6, and check the value in the Identity field.

Now, the Identity could either be a built-in account (such as NetworkService, LocalSystem, LocalService, or ApplicationPoolIdentity), or it could be a local or domain user (if you are using Active Directory).

If it is a local or domain user, you just need to open the 'C:\svn\Projects\xxx\trunk\xxx\Views\Shared\EditorTemplates' directory in Windows Explorer, right-click on it, and choose Properties. Click the Security tab, and make sure the user is in the list. If not, click Edit..., then click Add..., and add the user to the list. Ensure it has enough permission to read the directory.

If using a built-in user, you could either switch it to a local user, or see this answer for the command to add permissions to the built-in account.

templateName Parameter

One thing in particular to check is the templateName parameter of @Html.Editor() or @Html.EditorFor() in all of your views (or anywhere else you may happen to be calling it). This parameter should correspond with one of the formats here.

The most common usage is to specify just the name of the template. For example, if you specify MyTemplate for this field, it will search several directories for the file (see the above document), ending up with ~/Views/Shared/EditorTemplates/MyTemplate.<extension>, where extension will be .cshtml, .vbhtml, .aspx, or .ascx. This is the directory in your error message, so you should check these references thoroughly.

Even if you are not specifying the parameter explicitly, MVC uses a convention that the file name matches your view model name.

File Format

This is a long shot, since your application is running under IIS Express it shouldn't be the case. But you could try searching to see if there is any code in your application specifying a file in the 'C:\svn\Projects\xxx\trunk\xxx\Views\Shared\EditorTemplates' directory.

If so, make sure that the file name

  • Doesn't contain invalid Windows filename characters.
  • Is an absolute path, or is calling Environment.MapPath or Server.MapPath to resolve to an absolute path.
  • Doesn't contain a ? or a *.
  • Doesn't have a directory specified where a file name should be.

Clear your Temporary ASP.NET Files

I found a potential answer here.

You could attempt to clear your ASP.NET temporary files pertaining to the current application. Note that there are a few different places where they can be lurking depending on your framework version and bitness.

  • <Drive>:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
  • <Drive>:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
  • <Drive>:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files
  • <Drive>:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files

If you have the project open in Visual Studio, it will not let you delete the relevant files. Ultimately, you should close Visual Studio before deleting the files, but I found that leaving it open on the first attempt is a good way to determine which of the folders contains the application in question because you will get a message that the files are locked. Knowing that location can be useful if you have additional problems.

like image 119
NightOwl888 Avatar answered Nov 15 '22 06:11

NightOwl888