.cshtml files displaying as plain html - asp.net

I am having a problem setting up a website hosted on Windows Server 2012. The website is just the default website you get when setting up a new "ASP.NET Web Site (Razor v2)" site. Then I simply published it using the "Publish Web Site" option in VS2012. I have also added the .cshtml extension in the MIME types. The server is running IIS v8 and .NET v4. The problem is when I visit the website this is how it displays:
http://i806.photobucket.com/albums/yy341/SamuelCB/Razor%20Error/Untitled.png
Is there anything I am missing?

Items to check:
rarely do MIME Types actually matter if IIS and ASP.Net are installed properly
don't mis-interpret this statement, I'm not saying MIME types don't matter, just that if/when configured properly all of this, IIS/ASP.Net is "out of the box" without mucking with MIME types.
The issue with adding ".cshtml" manually is that IIS will (now) serve it, but the ASP.Net engine isn't (necessarily "there" for) handling it (e.g. integrated mode). That's why you're seeing the "unparsed" (raw) version of the file...code and all...it's all IIS (no ASP.net engine is configured to handle it).
if you run your own box, run Web Platform Installer - and it should give you insight on what's installed vs. what's not. Pay attention to ASP.Net bits and versions. You may need to (re)register ASP.Net
if you're hosted, just because your host has .Net Framework 4.x installed, doesn't mean they have all the bits and pieces of ASP.Net installed as well. Ask your host for guidance instead of doing a guessing game. I often have to "load" things that my dev machine has "by default" (of course its my machine) because I end up with non-functioning stuff when deployed to my host. You're not even getting an ASP.Net engine error, so that's a sure sign ASP.Net needs some work.
Nuget is excellent for this task. Some items that might be necessary to be "bin deployed" (aka. you have to add them to your deployment/upload to /bin directory on your host):
Microsoft ASP.NET Razor
Microsoft ASP.NET Web Pages
Microsoft.Web.Infrastructure
Unrelated: This sounds more like it should go to ServerFault rather than here on SO...I don't mind...but the community may think differently...and you might even get better answers....
Hth...

Related

Asp.net website not starting default.aspx (apache 2.4 on Windows 10 Pro; IIS 10)

So, I setup a Win10 box as an Apache server; built VS19 Asp.net webforms app, which works as expected when run in VS. published to the C:\Apache24\htdocs folder. Now, I setup port forwarding on my ISP-provided "Internet IP Address" to point to my local server. If I use any browser (outside of my LAN) to access that address (e.g. http://xx.yy.zz.qq - not showing actual IP for security reasons) I will see the page titled "index of /", and the list of files that I published to that htdocs folder. If I put in INDEX.HTML file in that folder, it will be displayed; but since I see Default.aspx as the 1st entry in the IIS Default Documents list, with NO index.html present, I still just see the list of files, not the aspx. I don't think the fact that I've not yet established a DomainName-to-IP binding should make any difference to this issue, but I can't be sure. Any thoughts? As you might guess, I've not done this before! :) ). TIA!
Jim
I made sure that the VS instance of the website was not running, just in case that might cause IIS confusion; but I don't think that would be the case.
As noted, I can't see how a non .net server going to run/launch/process correctly aspx pages that require IIS as the web server?
I mean, IIS can't run a web site designed for Apache, nor can say IBM "web spere" web server either.
I am trying "hard" to think how a application built in .net framework going to work with a web server that not designed to work with the .net framework?
I mean, if you have a computer, and have a word document, then you need word installed to work with that document.
If you have a PDF file on your computer, then you have to install some PDF software to use that PDF document.
A web server is not some "magic" box, but is a plane jane computer, with some software installed on it. So, if you build a aspx .net framework site in .net, then that computer will require the .net framework to have been installed, and require the correct type of software to work with those pages - in this case IIS.
Now, to be fair, you CAN do this with .net core, since .net core can run on quite much "any" computer (that supports nigex). However EVEN in that case, they FAKE and TRICK you, since how they achieve this "magic trick" is when you build the .net core application, the build process includes a WHOLE WEB SERVER as part of the build!!! (this lighter weight web server (kestrel) thus can work if you forward the ports and requests say from Apache, or quite much any web server. But MAKE NO MISTAKE here, a WHOLE .net core compatiable web server is included in that build, and thus that .net web server IS STILL required to run that .net code.
Unfortunately, the .net framework (as opposed to the .net core choice) does not upon build of your web site INCLUDE that WHOLE WEB SERVER as part of the build.
So, .net framework sites requite the correct software to work, and that correct software in this case is the web server called IIS (Internet Information Services).
You can no more suggest/attempt/assume that some program to load and read a PDF document is now out of the blue going to consume and work with Excel files, or word files.
hint:
Software build to a particular library of code requires the correct software to run and work. Kind of simple!!
So, a computer with a web server?
That is JUST a computer with software installed on it, and you need the correct software installed on that computer to consume the files etc. it was designed form.
Apache web server can no more consume a "application" or "web site" designed for IIS then it can consume other files etc. that are designed for use with a 100% different application. this is how all software works, and it not clear why you would think that Apache, or IIS, or word or Excel would work any different at all here?
Now, there was the "mono" project, and that was a port of .net framework that allowed the .net framework to run say on Linux, and there are some examples of some attempts to run aspx pages that way, but it is a galactic mess of epic proportions, and really not the way to go.
However, as stated, the .net core system DOES run on just about any platform, and it does have the above "magic trick" of being able to run on Apache, but behind the scenes, that software build actually includes a WHOLE WORKING web server that is .net core compatible, and that WHOLE web server is included with your build, and thus some are "fooled" by this magic trick that .net core web sites can run on Apache. They look like they can, but they are not, and in that example case (of .net core, NOT .net framework), the site seeming to work on the Apache web server? Nope, what occurs is the Apache web server simple hands off any web request to the REAL WORKING AND INSTALLED .net core web server!!! (thus Apache really only acts as a router, or "hand off" machine, and all the REAL web processing occurs in the .net core web server called kestrel).
So, you can do as you ask, but you would have to dump "web forms" and build the web site with aspx pages as a .net core web site. If you do that, then YES you can use Apache, and it will work, but behind the scenes, it ONLY works because that build process of the .net site ALSO includes THAT WHOLE COPY AND WORKING COPY of a .net core web server as part of the build. As noted, this magic trick option during the build process is NOT available for .net framework, but is most certainly available for the .net core choice.
So, in your case of using Apache? Software designed for a particular type of web server must use the correct type of web server. Same goes for IIS - it can't consume nor run a web site designed for Apache. I mean, how software works on your desktop is not any different then how software on a web server
The pages you have implemented with the .aspx are part of the ASP.NET Web Forms framework. This framework is part of the .NET Framework. The main server required to host Web Forms applications is IIS (Internet Information Services). Since you are working on a Windows machine, you can research how to setup IIS to host your Web Forms site if you wish. If you still want to use Apache as the front end for your site, you can even have it proxy requests to your site hosted in IIS, although there's probably little benefit and much complexity from such a setup.
Apache out of the box does not include support for hosting Web Forms applications. There is an open source project called Mono that seeks to implement an alternative version of .NET Framework and allows the use of alternative web servers such as Apache. But Mono has largely been superseded by .NET Core.
.NET Core is the official replacement for .NET Framework. It is open source and cross platform by default, and the ASP.NET Core web framework that runs on .NET Core includes a Kestrel web server. This can be utilized with Apache (or any other web server) in front of it, acting as a reverse proxy. It is not a magic trick, but a rather standard approach for web applications these days. However, ASP.NET Core does not include the Web Forms framework, so you would need to re-implement your application in a more modern alternative that's supported by ASP.NET Core if you intend to stay in the .NET ecosystem. There are many alternatives in ASP.NET Core including MVC, Blazor, Razor Pages, and Web API.

Am running the web allication using asp.net.am getting this error

HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /webctrl_client/1_0/treeimages/Rminus.gif
I had this problem for a simple reason. Make sure you compile your site before deploying it. I had some pages that were compiled and some pages that were not compiled. And because I was testing on a Windows Server 2008 box, not a Windows 7 box.
It took me so long to figure out because when I tried viewing these pages on the application server (Windows Server 2008), it wouldn't let me view a non secure page (http protocol), because of Internet Explorer's security settings. I only had a binding for port 80 when testing on a browser on the server box. So I couldn't even see the aspx page that was compiled, let alone the aspx pages that were not compiled. A plain HTML page was visible on both boxes however, on the same site--that part was interesting. So that told me IIS was running fine. When I viewed the pages on another machine (running Windows 7) on that network, the compiled aspx page showed up fine because it was compiled. And the non-compiled pages did not.
Here are other possible issues:
(use correct version of .NET framework for commands below)
1.) Have you installed the .NET framework?
2.) Make sure ASP.NET 4.0 is registered. Run these commands to verify.
"%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe" -lv
"%systemroot%\system32\inetsrv\appcmd.exe" list apppool /managedRuntimeVersion:v4.0
"%systemroot%\system32\inetsrv\appcmd.exe" list config -section:system.webServer/isapiFilters
If not, run this:
"%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis" -i -enable
3.) Make sure the ISAPI filters are turned on for the version you are using. Click server (not the site) in IIS 7. Then go to "Isapi Filters". Allow the ones you need.
4.) Make sure your application pool is running in the version of your compiled source code of your ASP.NET pages. Go to Application Pools in IIS, then right click the application pool for your site, and choose Advanced. Change the version to either 2.0 or 4.0. Make sure it's also 32 bit if you compiled your app as 32 bit.
... when reading forums those are the 4 solutions I came across most frequently. Mine was a bit simple, but confused me for hours because I hadn't installed the SSL certificate yet.

IIS 6 to 7 is making me scared of web.configs

Hi guys,
We have a mixed development environment of three servers running: Win Server 2003 & 2008, IIS 7 & IIS 6, ASP.NET 2.0 & ASP.NET 3.5. Previously, all three servers were Server 03/IIS6/ASP.NET 2.0, but with this new change, I am finding that pushing/moving any applications from server to server is always a terrifying experience because there are always a variety of problems with the web.config from server to server. I used to consider myself a confident ASP.NET developer but now I am frightened to come to work every day.
I have always used the web.configs that VS generates for me on the Win 2003/ ASP.NET 2.0 server. None of our web.configs are "leet", they are just normal, although we do use ScriptManager and UpdatePanel.
To get by, as a temporary fix, I'm having to remember that when projects are moved/tested/deployed, never to move or overwrite any web.configs and things get confusing very fast. I've tried "ducttaping" like suggested here my web.configs with the new IIS7 stuff but even that doesn't work all the time.
What can I do here, what's going on? Is there a standard web.config that will work on all of the servers and do the UpdatePanel and ScriptManager ?
[edited question]
Since IIS6 is the baseline install for your application, you should make sure to run the application in "Classic" mode under IIS7. This makes configuration the same as an IIS6 box. This is how we run our web applications for now until we have fully migrated to 100% IIS7 server environments and we have zero problems with deployment/runtime.
To do this you can either choose to run your app under the built in "Classic .NET AppPool" that comes with IIS7 or, assuming you create your own custom application pools, just make sure you set the "Managed Pipeline Mode" to "Classic" under the "Advanced Settings" dialog for the app pool.
You should seriously look at web deployment projects for visual studio 2008.
This is an official add-on for Visual Studio that gives you a new project type called web deployment project. Among the most useful features is the ability to do web.config search/replace as well as pre-compiled builds of your web sites or web application projects.
In your case, what you'd do is create a solution configuration in visual studio for all of your target web servers. Then you'd create a web deployment project for your web app. In the properties for the deployment project you tell it how you want to compile the project and what web.config replacements you want to use for each solution configuration.
The end result should be that you can open Visual Studio, pick a solution configuration, build the deployment project. The build will create a folder with everything you need for that environment including the correctly configured web.config files. Then you just copy the folder to your server and you are up-and-running.
Best of all, since the different config files are all stored in the projecct, it lets you manage your configuration in one place and check it all into source control.
Do note that there is no equivalent in Visual Studio 2010. Instead, VS 2010 has a whole new deployment mechanism called MSDeploy. With 2010 you don't need a seperate project for deployments, and MSDeploy goes a lot further allowing you to package your SQL databases and other stuff too.
You can use the Classic mode under IIS6 by changing the process. That is actually pretty simple and it should work.
Another approach would be to automating your deployment process and have it so that it deploys the correct web.config to the server when you need to update your application.
If you run your IIS 7 websites using the Classic .NET App Pool, then the config files will match what you would use for IIS 6. That's probably the easiest thing to do until you're ready to migrate everything to IIS 7.
Knowledge is a great way to get over fear. Figure out what's going on (you're currently grasping at straws) and the fear will go away.
It's my guess that you'll do better if you refactor the code that uses the config file. Sloppiness there can definitely explain your weirdness and inconsistencies. You can't control much with your config settings if the code isn't behaving properly.

page is not served because it has been explicitly forbidden - extension .asp may be incorrect

I'm trying to run a test version of a web using the File System (i.e. the "Cassini" web server built-in to Visual Studio 2005) rather than (IIS 5.1 on my Win XP dev PC). This web is a hodge-podge of classic ASP files written years ago and some new development in ASP.NET (VB.NET).
How can I get past this error message as it tries to go to /TestWeb/default.asp? -
Server Error in '/TestWeb' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.asp' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /TestWeb/default.asp
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082
Things I have checked and previously encountered trying to get this mess working:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config
(has nothing for *.asp nor
HttpForbiddenHandler so nothing to
comment out).
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config
(has nothing for *.asp)
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG\machine.config
(had a HTTPForbiddenHandler for
*.asp but I commented it out as per other postings advice; seemed to
have no effect for me though).
To get past an earlier error
("Request for the permission of type
'System.Web.AspNetHostingPermission'
failed"), I had to go to
"Administrative Tools > MS .Net
Framework 2.0 Configuration > My
Computer> Runtime Security Policy >
change Local Intranet to Full Trust.
To get past an earlier error ("the
network bios command limit has been
reached") I had to "enable a hot
fix" by adding the following DWORD
value at the following registry key:
HKLM\Software\Microsoft\ASP.NET\FCNMode
and set the value to 1 (per MS KB
Article 911272).
This whole web has been placed on a file server in our LAN and from my desktop VStudio2005 views it via the mapped drive letter (e.g. V:\SVNwork\myFolder\TestWeb)
Visual Studio 2005 models this as a "web site" (not a "web application project").
The remainder of this post describes some background about why I am trying this:
We tend to recreate the web site on our dev PC's which run IIS 5.1 on Win XP. Movement of new stuff into production can be awkward using WinDiff and copying files as needed.
I'm trying to implement source control over this work. I've had a heck of a time trying to configure Visual SourceSafe 2005 and local IIS to work together smoothly (interestingly, I had pretty good luck putting "web application projects" under VSS2005 so I think it's related to the awkwardness of the ASP.NET 2.0 "site" model and VSS).
Anyway, I've moved a development version of this classic ASP and ASP.NET to a common file server in our LAN. Before placing this under Subversion control as a working copy of it's equivalent imported into a repository, I just want to make sure it can work with the Cassini web server. That's where I am stuck. The ultimate goal is have this under SVN and view differences with TortoiseSVN.
Thanks for reading this far...hopefully someone can get me past this error and then I can move forward with the SVN and TortoiseSVN work.
Cassini doesn't, as far as I can tell, support classic ASP. An alternative would be to run a local install of Apache (since you can't/won't use IIS) which will host ASP, but is probably asking for trouble.
See also: http://blogs.msdn.com/mikhailarkhipov/archive/2005/06/24/432308.aspx
You could also run local IIS, which will, of course, host both ASP.NET and classic ASP. Visual Studio can easily be configured to debug with a local IIS install.
Points for moving to subversion: we use the Microsoft stack (Visual Studio, ASP.NET, SQL Server) with subversion and it works very well.
Subversion comment
GRRR.. bosses are fun. The svn model is known as copy/modify/merge. The repository lives in a central location - probably your file server. Using the svn client - or a Visual Studio plugin like the excellent AnkhSVN - each developer gets a LOCAL working copy,makes their changes and performs a "commit" when they're done working on a file.
SVN takes care of making sure that developers don't overwrite each others changes, provides a facility for merging changes when someone has modified a file between when you got your last copy and when you commit your changes, etc.
The whole point of a working copy is that it isolates developers from each other. The merge/commit step takes care of intergrating everyones changes. Having a central working copy that everyone works from defeats the purpose.
This is a very different approach than that used by Visual SourceSafe, which is basically a file locking mechanism. The fact that SVN is a real client-server application (where VSS is simply a disk-based "database" with no server app to administer it) provides all sorts of capabilities. We check out, modify, commit, then publish from svn to a dev server.
Also, if I remember correctly, Cassini won't server apps from a mapped drive.

ASP .NET Development Server not serving everything all the time

I'm using Visual Studio 2005 on a Windows XP SP3 machine and recently have come accross a some what strange issue.
I have a C# and ASP.NET project that runs fine when on the team test server and using IIS locally on my own machine. However, running it using the in-built Visual Studio ASP.NET Development server it doesn't seem to serve all the images/scripts/css files all of the time. When I load a page one time images A, B and C will be missing and I may get a system (sub-package) error however loading it again all those images will be there and the sub-package will work but a CSS, a script or any other image file may be missing.
The Windows event application log seems to show occasionally the missing files will be logged but this isn't consistent either.
It happens to me all the time; I think the reason is that the ASP.NET Develoment server is not a very good HTTP server, and when receiveing too many requests, it drops some ones.
Since it is also very very slow, I configured vs2008 (you can do that with vs2005, of course) to use ASP.NET for debugging; it works far better that way.
To do that:
Project -> properties -> Web (last tab) -> Server. There are three alternatives: Use Visual Studio Development Server; Use local Web IIS; Use custom Web server. Choose the second. (not sure about the exact english names: I have the Italian version of VS).
Check the page in Firefox/Firebug or with IE8 and see if the paths to the files/scripts/images is correct or not. A common problem when switching between the local dev webserver and IIS hosted pages is that the paths may not resolve the same. You can fix this sometimes by using the "~" character before a path in the asp code.

Resources