ASP.NET MVC和两个Web.config文件中 [英] ASP.NET MVC and two Web.config files

查看:668
本文介绍了ASP.NET MVC和两个Web.config文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里的Web.config应该在ASP.NET MVC项目去了?

Where is the Web.config supposed to go in an ASP.NET MVC project?

我只是遇到了一个错误试图做到这一点:

I just ran into an error trying to do this:

_cnstr = System.Configuration.ConfigurationManager.
    ConnectionStrings["production"].ConnectionString;

默认模板MVC提出的Web.config在项目的根目录。

The default MVC template puts the Web.config at the root of the project.

如果你去到一个项目(与垂直选项卡屏)的属性。进入设置,并尝试创建一个应用程序的设置,它会提示你,你没有一个配置文件。当创建文件时,它做它在浏览文件夹的基地。所以现在我有两个的Web.config文件。这是怎么应该是什么?

If you go into the properties of a project (the screen with the vertical tabs). Go to settings and try to create an application setting, it will prompt you that you don't have a config file. When it creates the file it does it at the base of the Views folder. So now I have two Web.config files. Is this how it supposed to be?

和我想我应该把我的连接字符串中的意见web.config文件,以避免错误。
思考?这是在ASP.NET MVC位的上一版本中的错误?

And I guess I should put my connection string in the "views" web.config to avoid the error. Thoughts? Is this a bug in the last release of the ASP.NET MVC bits?

更新:
见大卫的回答

UPDATE: See David's answer

推荐答案

的设置应该进入在应用程序根目录中的web.config。在意见文件夹中的web.config是有阻止哪个应该只打通控制器提供服务的视图aspx页面的直接访问。

The settings should go into the web.config at the application root. The web.config in the views folder is there to block direct access to the view aspx pages which should only get served through controllers.

(和:我想我的机器上创建应用程序设置,安装ASP.NET MVC RC 1,使用新创建的MVC Web应用程序,他们被添加到应用程序根目录中的web.config。)

(And: I tried creating application settings on my machine, with ASP.NET MVC RC 1 installed, using a newly created mvc web application. They get added to the web.config at the application root.)

这篇关于ASP.NET MVC和两个Web.config文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆