TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sed Iman
NA
1
736
Font, Javascript & Css not loading
Jul 8 2015 3:34 AM
I have a http C# server. I can access index.html on a client browser over the network. However, the linked fonts, javascript and css file are not loading. Apparently, this is due to the fact that the server only sends ".html" files. THe sample code is where I suspect the problem is from. I've been trying to fix this for days...HELP please
public override void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp)
{
string path = this.Folder + "\\" + rq.URL.Replace("/","\\");
//..%2f Buf fix
if (path.Contains(".."))
{
string bodyStr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
bodyStr += "<HTML><HEAD>\n";
bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n";
bodyStr += "</HEAD>\n";
bodyStr += "<BODY><p>The requested URL contains \"..\" used for many malicious attacks!<p>\n";
bodyStr += "</BODY></HTML>\n";
rp.BodyData = Encoding.ASCII.GetBytes(bodyStr);
return;
}
//
if (Directory.Exists(path))
{
if (File.Exists(path + "index.html"))
path += "\\index.html";
else
{
string[] dirs = Directory.GetDirectories(path);
string[] files = Directory.GetFiles(path);
string bodyStr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
bodyStr += "<HTML><HEAD>\n";
bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n";
bodyStr += "</HEAD>\n";
bodyStr += "<BODY><p>Folder listing, Add an 'index.htm' document to navigate to\n<p>\n";
for ( int i = 0; i<dirs.Length; i++)
bodyStr += "<br><a href = \"" + rq.URL + Path.GetFileName ( dirs[i] ) + "/\">[" + Path.GetFileName( dirs[i] ) + "]</a>\n";
for ( int i = 0; i<files.Length; i++)
bodyStr += "<br><a href = \"" + rq.URL + Path.GetFileName( files[i] ) + "\">" + Path.GetFileName( files[i] ) + "</a>\n";
bodyStr += "</BODY></HTML>\n";
rp.BodyData = Encoding.ASCII.GetBytes(bodyStr);
return;
}
}
if (File.Exists(path))
{
RegistryKey rk = Registry.ClassesRoot.OpenSubKey(Path.GetExtension(path), true);
// Get the data from a specified item in the key.
String s = (String)rk.GetValue("Content Type");
// Open the stream and read it back.
rp.fs = File.Open(path, FileMode.Open);
if ( s != "")
rp.Headers["Content-type"] = s;
}
else
{
rp.status = (int)RespState.NOT_FOUND;
string bodyStr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
bodyStr += "<HTML><HEAD>\n";
bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n";
bodyStr += "</HEAD>\n";
bodyStr += "<BODY>File not found!!</BODY></HTML>\n";
rp.BodyData = Encoding.ASCII.GetBytes(bodyStr);
}
}
When I use the folder listing to navigate to any css, or javascript file the browser says "SERVER SENT NO DATA"
I am 100% sure the problem is not from my html document, because it works when I copy the whole folder to any client.
Reply
Answers (
0
)
print bill
Sending messages and images via mms in asp.net C#