本文介绍了我可以使用ASP.NET网页,无需部署"箱位QUOT;夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个非常简单的网站,原来只是一堆HTML / CSS文件。然后我需要添加服务器端逻辑的一点点,所以我想我会使用ASP.NET网页,因​​为他们听起来像一个合适的解决方案。

I am creating a very simple site that was originally just a bunch of HTML / CSS files. Then I needed to add a little bit of server-side logic so I thought I'd use ASP.NET Web Pages as they sound like a suitable solution.

于是我改变了 index.html的 index.cshtml ,增加了code,我需要和我虽然这将是它(我还添加了这个基本的的web.config 文件:

So I changed index.html to index.cshtml, added the code I needed and I though that would be it (I also added this basic web.config file:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
</configuration>

不过,推出这一本地IIS防爆preSS产生这个错误:

However, launching this on local IIS Express yielded this error:

无法确定使用哪个ASP.NET网页版本。

为了使用本网站,指定该网站的web.config文件中的版本。有关详细信息,请参阅Microsoft支持网站的以下文章:

In order to use this site, specify a version in the site’s web.config file. For more information, see the following article on the Microsoft support site: http://go.microsoft.com/fwlink/?LinkId=254126

所以,我已将此添加到我的的web.config

So I added this to my web.config:

<appSettings >
    <add key="webPages:Version" value="2.0" />
</appSettings >

现在该网站启动,但处理UTF-8真的古怪 - 虽然所​​有的HTTP头,文件编码和meta标签是否正确设置为UTF-8,我的民族文字显示不正确。我发现这个问题:但它并没有真正解决我的问题。

Now the site starts but handles UTF-8 really weirdly - although all the HTTP headers, file encodings and meta tags are correctly set to UTF-8, my national characters display incorrectly. I found this question: Do I need web.config for non-ASCII characters? but it didn't really solve my problem.

不过,我觉得,有什么可以是错误的我的设置?当我创建在WebMatrix中一个新的网站,我复制文件到它,这一切工作正常,即使没有在的web.config 指定网页版本。我可以看到的唯一区别是在WebMatrix中生成项目文件夹中的presence。

I though, what can be wrong with my setup? When I create a new site in WebMatrix and copy my files over to it, it all works fine, even without specifying the Web Pages version in web.config. And the only difference I can see is the presence of bin folder in the WebMatrix-generated project.

所以现在的问题是,我的需求的有文件夹作为我的来源一部分的文件吗?我真的不觉得自己像检查的二进制文件到Git的1.5MB的价值应该是必要的只是在我的index.cshtml添加一个动态线,但也许这是怎么回事?

So the question is, do I need to have the bin folder as part of my source files too? I don't really feel like checking 1.5MB worth of binary files into Git should be necessary just to add one dynamic line in my index.cshtml but maybe that's how it is?

感谢要么确认这个或展示我一些更好的办法。

Thanks for either confirming this or showing me some better way.

推荐答案

ASP.NET网页需要在UTF-8页的BOM,否则将无法读取页面为UTF-8。如果不这样做,也不会输出UTF-8 EN codeD页。

ASP.NET WebPages requires a BOM on UTF-8 pages or it won't read the page as UTF-8. And if it doesn't do that, it won't output a UTF-8 encoded page.

这是不是一个ASP.NET问题,而是一个网页的问题。网页处理真正的页面,它不跨preT的HTML知道,它应该是UTF-8。它知道的唯一方法是通过寻找一个BOM。

This isn't an ASP.NET issue, but rather a WebPages issue. WebPages processes the real page, and it doesn't interpret the html to know that it should be UTF-8. The only way it knows is by looking for a BOM.

这篇关于我可以使用ASP.NET网页,无需部署&QUOT;箱位QUOT;夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:50