In Cassini, unlike IIS,
all files except for the /aspnet_client scripts are passed to the HttpRuntime. In IIS, only those extensions that are mapped to the ASP.NET Isapi Extension will be processed by the runtime.
The problem with this is that if you enable forms authentication and static resources like images, stylesheets, and XML files are stored in a protected folder, ASP.NET will deny access to them until the user is authenticated.
I noticed the first time I enabled forms authentication and set <deny users="?" />. When I was sent to the Login page, none of the images or stylesheets were loaded!
To work around this:
1) Create a new folder called 'public' and move all your static files there
2) Add a new Web.config file in the 'public' folder with the contents:
<configuration>
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</configuration>
This folder will allow all users access, so only put files in there that you don't want protected.
Another option would be to hack Cassini to check the file extension of the request. If it's one of the ASP.NET files, then send it to the runtime, otherwise send it directly to the client.
Add this method to the Request class.
private static String[] s_aspNetExtensions = new String[] {
".asax", ".ascx", ".ashx", ".asmx", ".aspx", ".axd",
".vsdisco", ".rem", ".soap", ".config", ".cs", ".csproj",
".vb", ".vbproj", ".webinfo", ".licx", ".rex", ".resources" }
private bool ProcessStaticFile()
{
if (_verb != "GET")
return false;
// check if file exists
if (!File.Exists(_pathTranslated))
return false;
// last element extension-less?
int i1 = _pathTranslated.LastIndexOf('\\');
int i2 = _pathTranslated.IndexOf('.', i1);
if (i2 < i1)
return false;
string extension = _pathTranslated.Substring(i2);
// loop through extensions
foreach (string aspNetExtension in s_aspNetExtensions)
{
// is it ASP.NET? if so, get out of here
if (extension == aspNetExtension)
{
return false;
}
}
// must be a static file, so send the file directly to the client
_conn.WriteEntireResponseFromFile(_pathTranslated, false);
return true;
}
Then add a call to ProcessStaticFiles() in the method Request.Process()
public void Process() {
[snip code]
// special case for directory listing
if (ProcessDirectoryListingRequest()) {
return;
}
// static files
if (ProcessStaticFile())
{
return;
}
PrepareResponse();
// Hand the processing over to HttpRuntime
HttpRuntime.ProcessRequest(this);
}
Good luck!
Kiliman