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?

5
  • How many webconfig files do you have ? more than one? Commented Apr 17, 2015 at 21:22
  • yes, one in project and one in View folder. When I delete the one in view then it does not recognize my views. Commented Apr 17, 2015 at 21:28
  • Both of them has <authentication mode="Windows"/> ?? If yes, delete it in the view and check Commented Apr 17, 2015 at 21:31
  • stackoverflow.com/questions/4725387/… Commented Apr 17, 2015 at 21:53
  • @nikoom not sure if you are still having issues but I edited my answer with another workaround. Commented Apr 21, 2015 at 13:10

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
Ok I tried both these ways, the <PropertyGroup> does not solve the problem and also with changing the name of web.config the views are not loading any more.
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)

10 Comments

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.
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.
@JacobRoberts nothing in this life is random. there is ALWAYS a reason.
@Alundrathedreamwalker I'm talking from personal experience... random or not, it happened and fixed itself without any environment changes.
@JacobRoberts +1 but i still believe something changed to make it work for you
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.