5

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.

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>

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

Could not determine which version of ASP.NET Web Pages to use.

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

So I added this to my web.config:

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

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.

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.

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.

Community
  • 1
  • 1
Borek Bernard
  • 50,745
  • 59
  • 165
  • 240
  • Try using .aspx parser instead and see what happens? What version of VS are you using? – IrishChieftain Sep 29 '12 at 22:49
  • Huh there is one other subtle difference - the WebMatrix-created site uses BOM while my index.cshtml file doesn't. ASP.NET cannot work on non-BOM files? I wouldn't believe that. – Borek Bernard Sep 29 '12 at 22:56
  • Anyway, the question stands - do I need or do I need not to include the `bin` folder, possibly also the `App_Data\packages` folder that Web Matrix generates for new projects? – Borek Bernard Sep 29 '12 at 23:03

1 Answers1

1

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.

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.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • Thanks, adding `` fixes it. However, the original question still stands - do I or do I not need to deploy with `bin` and `App_Data\packages` folders? – Borek Bernard Sep 29 '12 at 23:09
  • 1
    It depends on whether or not the WebPages, Razor, Infrstructure, etc.. dll's are in the GAC on the server or not. Did you install WebPages on the server? Anything not installed in the GAC will have to be bin-deployed. Also, i'm not sure what deploying has to do with checking things into Git. – Erik Funkenbusch Sep 29 '12 at 23:13
  • For instance, I'll probably use Azure Web Site to host this and Git is a deployment mechanism there. I'll probably try to deploy there and see if it works with `bin` or not. Thanks. – Borek Bernard Sep 29 '12 at 23:52
  • 1
    @Borek - why on earth would you use Git to publish to Azure? Just use the Visual Studio Azure publishing wizard. – Erik Funkenbusch Sep 29 '12 at 23:59
  • @Borek - Sure, but you shouldn't then complain about the difficulties you face by going against the flow. – Erik Funkenbusch Sep 30 '12 at 06:33
  • I am not going against the flow, Git deployment is a first-class citizen on Azure Web Sites. But this is OT, really. – Borek Bernard Sep 30 '12 at 10:13
  • @Borek - I wasn't talking about Git being against the flow. I was referring to your reluctance to check in libraries that are needed on the server. If you're going to use git for deployment, you need to check everything into git. So you're going against the flow if you don't want to. – Erik Funkenbusch Sep 30 '12 at 18:28
  • Ah I may have misunderstood when you said "why on earth would you use Git to publish to Azure?". I don't want to go against the flow, that's why I've asked. The closest answer is second comment in this thread. – Borek Bernard Sep 30 '12 at 19:59