1

I have a windows Authentication for My MVC5 projec. It is working locally but when I publish it to the server, I get this error:

  It is an error to use a section registered as  allowDefinition='MachineToApplication' 
beyond application level. 
 This error can be caused by a virtual directory not being configured 
   as an application in IIS.

I have this line in my web.config

<authentication mode="Windows"/>

but in MVC there is another config file under the "view" as well. I also added to that too but same error. Any thought?

Alma
  • 3,780
  • 11
  • 42
  • 78

2 Answers2

1

This is one of those errors that really doesn't have a fix. You can try deleting all of your bin/obj files and see if that works. You can turn off the feature that pre-builds the view, which will probably resolve your issue but you lose other goodies like catching compile time exceptions on your views. You can stop the pre-publish builds on your view by editing Web.config like:

<PropertyGroup> 
    <MvcBuildViews>false</MvcBuildViews> 
</PropertyGroup>

An alternative to the PropertyGroup is, (VS2013) right click your project -> publish -> Settings -> (uncheck) Precompile during publishing. As with the previous mentioned, you will lose compile time exceptions on your views.

*And remove the change you added to the Web.config in your views folder.

Just for clarity, check out this SO discussion MVCBuildViews not working correctly

**Note: these are not fixes, just workarounds that may or may not work for you.

Community
  • 1
  • 1
Jacob Roberts
  • 1,725
  • 3
  • 16
  • 24
  • Thanks for your reply, but I kind of confused how my problem is going to related to the link that you just posted. Is it something in my view that i have to change? – Alma Apr 17 '15 at 21:24
  • Ok I tried both these ways, the does not solve the problem and also with changing the name of web.config the views are not loading any more. – Alma Apr 17 '15 at 23:17
0

Many reasons why you received that error message , but it's good you mentioned that is related to the production environment and no locally. I would suggest two things:

  1. Most likely you have nested web.config files.(Double check that)
  2. Did you check to make sure the folder was configured as an application? (In your IIS if you have access to it)
IndieTech Solutions
  • 2,527
  • 1
  • 21
  • 36
  • as I mentioned there are 2 config files. one in project one in View folder. I know maybe the problem is that but what can I do? About the second one yes it is application. – Alma Apr 17 '15 at 21:30
  • This is a random issue that happens out of the blue. Mine started happening when I changed computers and moved my VM. Not sure if that is just coincidence but I couldn't publish 2 of 4 websites to my Azure dev servers with 'Debug' build. If I changed the build to 'Release' it would publish fine. After I made the config change I mentioned in my answer, I was able to publish and a few days later a change the config back to pre-build the views and it started working again. If you read the exception, it will tell you the pre-build folder and config that is having the issue but doesn't help. – Jacob Roberts Apr 17 '15 at 21:39
  • @JacobRoberts nothing in this life is random. there is ALWAYS a reason. – IndieTech Solutions Apr 17 '15 at 21:40
  • @Alundrathedreamwalker I'm talking from personal experience... random or not, it happened and fixed itself without any environment changes. – Jacob Roberts Apr 17 '15 at 21:43
  • @JacobRoberts +1 but i still believe something changed to make it work for you – IndieTech Solutions Apr 17 '15 at 21:44
  • @nikoom the problem is because of nested web.config files look and see if you have in both of them. Also , can you share a link to your web.config files – IndieTech Solutions Apr 17 '15 at 21:47
  • @nikoom you can also remove "authentication" node on the nested web.config that might be the problem . hard to tell without having access to the web.config – IndieTech Solutions Apr 17 '15 at 21:50
  • @nikoom How did you publish your application to the production server? – IndieTech Solutions Apr 17 '15 at 21:53
  • @nikoom another thing you can try is to rename the web.config file you have under views and see – IndieTech Solutions Apr 17 '15 at 21:58
  • @Alundra the dreamwalker Thanks, for the publish I uses the publisg figure that is in vs2012. – Alma Apr 17 '15 at 22:36