Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (41 loc) · 1.44 KB
/
Copy pathProgram.cs
File metadata and controls
47 lines (41 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace HTTPServer
{
class Program
{
static void Main(string[] args)
{
// TODO: Call CreateRedirectionRulesFile() function to create the rules of redirection
CreateRedirectionRulesFile();
//Start server
// 1) Make server object on port 1000
Server srvr = new Server(1000, @"C:\Users\bradl\Desktop\redirectionRules.txt");
//2) start server
srvr.StartServer();
}
static void CreateRedirectionRulesFile()
{
// TODO: Create file named redirectionRules.txt
string path = @"C:\Users\bradl\Desktop\redirectionRules.txt";
try
{
using (FileStream fs = File.Create(path))
{
byte[] info = new UTF8Encoding(true).GetBytes("aboutus.html,aboutus2.html\r\n");
fs.Write(info, 0, info.Length);
}
}
catch (Exception ex)
{
Logger.LogException(ex);
}
// each line in the file specify a redirection rule
// example: "aboutus.html,aboutus2.html"
// means that when making request to aboustus.html,, it redirects me to aboutus2
}
}
}