Adam Haile
Adam Haile

Reputation: 31359

Cassini Error: "This type of page is not served"

I'm trying to use the Server class from Cassini to include a basic web server in my own application. I just started playing around with it to get familiar with the way the server works and I setup a simple app that is as follows:

    static void Main(string[] args)
    {
        Server server = new Server(80, "/", @"C:\Projects\");
        server.Start();
        Console.ReadLine();
        server.Stop();
    }

It lets me browse through the directories, however if I try to click on a file, a C# source file (*.cs) for example, it gives the following error:

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 '.cs' may be incorrect.
Please review the URL below and make sure that it is spelled correctly.

I tried searching for that error text in the Cassini libraries, but didn't find anything.

Where is this error coming from? How can I make it serve up any file? I know it's meant to do asp.net and HTML, but I want it to also server up any file like a normal server would.

Upvotes: 0

Views: 5402

Answers (2)

Kev
Kev

Reputation: 119846

.cs files and many source code types are prevented from rendering because they are handled by ASP.NET's forbidden file handler.

This is initially configured in the following setting in the master web.config in c:\windows\microsoft.net\v2.0.50727\CONFIG\web.config:

Look for in the <httpHandlers> section, you see settings like:

<add path="*.cs" verb="*" type="System.Web.HttpForbiddenHandler" validate="True"/>

Generally this is a good idea because it prevents casual browsing of your source code which may contain sensitive data such as connection strings.

You should be able to remove this restriction in your app's local web.config by doing:

<configuration>
   <system.web>
      <httpHandlers>
         <remove verb="*" path="*.cs"/>
      </httpHandlers>
   </system.web>
</configuration>

I probably wouldn't recommend doing this on a web facing production environment.

Upvotes: 2

smith
smith

Reputation: 11

Downloading and installing the MS ASP.Net Web Pages worked for me.

http://www.microsoft.com/download/en/details.aspx?id=15979

S.

Upvotes: 1

Related Questions