I am trying to get my server to run .cshtml files. Using WebMatrix 3 I can view the pages by right clicking and selecting "view in browser", but that views through a localmachine port. If I try to access the pages from the internet, I get a 500 error.
Here is what I have done:
I made sure that MVC 3 was installed (but I keep reading that MVC is not needed for .cshtml... I made sure anywway.
I did the whole "revert to parent" / "revert to inherited" thing, which is found in many blogs.
I was getting a 404 error for a while, so I added a MIME type of "text/html" to .cshtml extension. That solved that problem, but only led to my 500 error.
I am suspecting it's something to do with my web.config file because if I remove the file, the page will show, but it reads like text.
For example (in the most basic page I could think of):
#{
var currentTime = dateTime.Now;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Testing</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
</head>
<body>
The current time is #currentTime .
</body>
</html>
The page will render like:
#{ var currentTime = dateTime.Now;} The current time is #currentTime .
Yet, I am clueless as to what should or should not be in the web.config file. I have been wracking my brain over this for close to a month...
Here is what is in the web.config file:
<configuration>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add invariant="System.Data.SqlServerCe.4.0" name="Microsoft® SQL Server® Compact 4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<appSettings>
<add key="webPages:Version" value="2.0"/>
<add key="webpages:Enabled" value="true" />
</appSettings>
<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
Many thanks in advance.
If I understand you correctly you are having problems running this in IIS (Internet Information Services - the built in Web server on Windows). It looks like the directory you are serving is not configured as a Web Application (but it is configured as a Virtual Directory).
To fix this:
Open IIS manager (Win + R and copy %systemroot%\system32\inetsrv\iis.msc to the run window)
Navigate to your directory in the tree on the left (probably \Sites\Default Web Site\something
Right click on it and choose "Convert to Application"
These steps should make IIS at least try to render the .cshtml.
On a separate note .cshtml (ie ASP.NET MVC) is so much more easier to learn and understand than .asp (ie simply ASP.NET)
It seems that I had an older version... this was answered here:
CSHTML rendering text only - static page?
Related
I'm struggling to deploy any MVC application onto IIS in a windows 10 environment.
I always get an HTTP error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid. It goes on to suggest there is a problem reading the configuration file.
On a similar post on this site it was suggested that asp.net was not installed but I'm certain that I've done it. I've used the Aspnet_regiis.exe tool and followed the instruction on the link below.
http://www.jammer.biz/enable-asp-net-on-windows-10/
The webconfig file as it came out of visual studio 2017 when I published is as follows:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\HelloWorld.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: e88818e3-e6fd-4105-94cc-5be77ed93582-->
I've not edited it since none of the tutorials I've followed it tell me to.
I've made sure that full access rights on the folder are granted.
Here is the error message as seen from in IIS.
Why is IIS struggling to read my config file?
Thanks in advance.
Ian
I had this same issue when trying to publish a .NetCore2.0 mvc app. The solution can be found here: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/index?view=aspnetcore-2.1&tabs=aspnetcore2x
In my case, I did not have the .NET Core Hosting Bundle installed.
I'm having this weird problem when I set:
BundleTable.EnableOptimizations = true;
When I try to open my website it just won't load, when I open Chrome's console I see the following message:
GET /localhost/bundles/scripts/angularjs/commonmodules?v=13-uWpwzN3U6kiHVssXRdpywHxrn09twvYKwoDVN3SU1 404 (Not Found)
However, if I try to open the link shown on chrome's console, it loads just fine, in other words, the link is found when I try to open it directly, but the server (IIS 7.5) returns a 404 when a page tries to link it through a tag.
Have anyone been through such a weird behavior?
The virtual paths for my bundles do not map for any existing file or directory, I include them using the following code:
var myBundle= new ScriptBundle("~/bundles/scripts/angularjs/bootstrapping");
bootstrapping.Include("~/app/app.js")
.Include("~/app/config.js")
.Include("~/app/config.exceptionHandler.js")
.Include("~/app/config.route.js");
bundles.Add(bootstrapping);
And I already tried to add the following lines on web.config's system.webServer:
<modules runAllManagedModulesForAllRequests="true">
<remove name="BundleModule" />
<add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>
I'm not sure if this may be related, but I'm using Umbraco v7 on this website, and this only happens if I set EnableOptimizations to "true".
If I remember correctly it's umbraco config related.
Locate the key umbracoReservedPaths (in appSettings) in your web.config and add the path to bundles there, like so:
<add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/bundles/"/>
I have published a ASPX page with DCP.
<html>
<head>
</head>
<body>
<tridion:ComponentPresentation runat="server" PageURI="tcm:9-5251-64" ComponentURI="tcm:9-5245" TemplateURI="tcm:9-5247-32"/>
</body>
</html>
What are the ways to execute this page, so that it renders the DCP.
I just tried browsing this page through IIS, I am getting parser error.
Unknown server tag 'tridion:ComponentPresentation'
It would be great if some one can guide me to run this page.
Thanks in Advance
Make sure you have following tag in web.config and Tridion.ContentDelivery dll in bin
<configuration>
<system.web>
<pages>
<controls>
<add tagPrefix="tridion"
namespace="Tridion.ContentDelivery.Web.UI"
assembly="Tridion.ContentDelivery" />
</controls>
</pages>
</system.web>
You need to install the 'API Server Role' for your .NET web application:
http://sdllivecontent.sdl.com/LiveContent/content/en-US/SDL_Tridion_2011_SPONE/task_FF19F86A63E246F793D64495849EDEDF
(username/password required)
I have an host where I hosted a webpage with .cshtml extension. My host is arvixe.com that provides ASP and .NET hosting but when I try to load my web page I get this error message.
Server Error in '/' 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 '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /samples/WoT/Default.cshtml
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.276
I read something does I have to write something in my web.config file to make it work
like this
<compilation>
<assemblies>
<add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
<buildProviders>
<add extension=".cshtml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
</buildProviders>
</compilation>
But I tried everything, paste it in on different lines, nothing worked. What do I miss or do wrong?
I believe you are not making using the MVC feature and trying to load just the razor view outside views or custom Area folders.
Then you need to enable webpages key in Web.config which is disabled by default in .Net 4.0
<add key="webpages:Enabled" value="true" />
<appSettings>
<add key="webpages:Enabled" value="true" />
Repairing this in Windows 10 Pro using IIS 10 was a nightmare, it took two days but I was finally able to achieve the desired results using the following procedure:
Open your web site in Visual Studio. The way you do this is to go to File > New > Web Site and then select ASP.Net Empty Web Site AND before you click OK change the location to your project location. In my case I had my project in C:\inetpub\wwwroot\AspNet\Projects\Test
Open internet information services manager (click the "cortana" search and type IIS, it should show up as long as you have it installed). Locate your project folder under the ServerName > Sites > Default Web Site > ... , right click on it and click the "Convert to web Application" button. Accepting the defaults at the prompt by clicking OK should be sufficient in most cases.
Use the following Web.Config file, or something similar. NuGet may overwrite some settings but this isn't a big problem.
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301879
-->
<configuration>
<appSettings>
<add key="webPages:Version" value="3.0.0"/>
<add key="webpages:Enabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</assemblyBinding>
</runtime>
</configuration>
Delete your bin folder, and packages.config file, if they exist. This is because we must assume that something in that bin folder is corrupt since IIS is designed to run Razor/ASP. In your visual studio project you will need to refresh your project so it knows these files have been deleted. This can be done by clicking the refresh button in the menu on the top of the Solution Explorer frame. In you visual studio project go to Tools > NuGet Package Manager > Package Manager Console and enter the following two commands.
Install-Package Microsoft.AspNet.Razor -Version 3.0.0
Install-Package Microsoft.AspNet.WebPages
This was enough to get *.cshtml pages to be rendered by IIS 10 on Windows 10 Pro.
I seem to be having a problem with my visual studio 2005/2008 installation or something because it isn't providing any IntelliSense whatsoever for controls registered on web.config files in folders different from the root, but it isn't showing any errors neither. Is this behavior normal?
I have access only to the folder of my sub-app, so I can't modify the root's web.config file. Well I COULD, but I'm NOT allowed to.
What I'm trying is to register some WebUserControl's on the web.config file for my sub-app folder, so all the pages in my sub-app can use the WebUserControl's without having to register them on every page, but I'm not getting IntelliSense for those controls registered on the web.config file on my sub-app folder, but I do get IntelliSense if I register them on the root's web.config file. IntelliSense for everything else appears to be working fine.
In the web.config file on my sub-app folder I have something like the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<pages>
<controls>
<add tagPrefix="qme" tagName="EmptySearchMessage" src="~/QMinerals/WebUserControls/EmptySearchMessage.ascx"/>
<add tagPrefix="uc1" tagName="uc_general" src="~/uc_general.ascx" />
<add tagPrefix="uc1" tagName="uc_menu" src="~/uc_menu.ascx" />
</controls>
</pages>
</system.web>
</configuration>
am I doing something wrong?
Update
Now I have upgraded to VS2008 SP1 and the issue persist
Did you try removing "~" from the path and using it relative to web.config? (yeah, even if works now)
Do you have Visual Studio 2005 Service Pack 1?