Beispiel #1
0
 // 添加路由规则
 static void RegisterRoutes(Routing route)
 {
     route.AddRoute("Home", "{controller}/{action}/{id}",
                    new { controller = "Home", action = "details", id = UrlParameter.Missing });
     route.AddRoute("Index", "{controller}/{action}",
                    new { controller = "Home", action = "Index" });
     route.AddRoute("Indexhtml", "{controller}/{action}",
                    new { controller = "Home", action = "Index2" });
     route.AddRoute("test", "{controller}/{action}/{firstName}/{lastName}",
                    new { controller = "test", action = "test", firstName = UrlParameter.Optional, lastName = UrlParameter.Missing });
 }
Beispiel #2
0
 protected virtual void Application_Start(Object sender, EventArgs e)
 {
     Routing.AddRoute("test", PatternTypes.Simple, "/test1", () => { return(new TestHandler()); });
     Routing.AddRoute("test2", PatternTypes.Simple, "/test/{id}", () => { return(new TestHandler()); });
     Routing.AddRoute("login", PatternTypes.Simple, "/login", () => { return(new TestHandler()); });
     Routing.AddRoute("logout", PatternTypes.Simple, "/logout", () => { return(new TestHandler()); });
     Routing.AddRoute("whoami", PatternTypes.Simple, "/whoami", () => { return(new TestHandler()); });
     Routing.AddRoute("test3", PatternTypes.Simple, "/test3/{id}/{action=[view]}/{*}", () => { return(new TestHandler()); });
     Routing.AddRoute("test4", PatternTypes.Simple, "/test4", () => { return(new TextHandler("I'm test 4!")); });
 }
 //Route: Conditional
 public void AddRoute(Func <HttpRequest, bool> condition, Action <HttpRequest> action)
 {
     Routing.AddRoute(condition, action);
 }
 public void AddRoute(string url, ControllerDescriptor descriptor)
 {
     Routing.AddRoute(url, descriptor);
 }
 //Route: Controller
 public void AddRoute <T>(string url)
 {
     Routing.AddRoute <T>(url);
 }
 //Route: Action
 public void AddRoute(string url, Action <HttpRequest> action)
 {
     Routing.AddRoute(url, action);
 }
Beispiel #7
0
        protected virtual void Application_Start(Object sender, EventArgs e)
        {
            FSCAuth.UserStore                   = new MongoUserStore();
            FSCAuth.Config.SiteName             = "Last Year's Wishes";
            FSCAuth.Config.LoginPage            = "/login";
            FSCAuth.Config.UniqueHash           = Config.UniqueHash;
            FSCAuth.Config.CookieHttpOnly       = true;
            FSCAuth.Config.CookieSecure         = false;
            FSCAuth.Config.CookieUseBase        = true;
            FSCAuth.Config.CookieUseBrowserInfo = false;
            FSCAuth.Config.CookieUseIP          = true;

            SimplePattern.AddShortcut("dateslug", "/{Year}/{Month}/{Day}/{Time}/{*}");

            //blog routes
            Routing.AddRoute("index", HttpMethod.Get, "/", (r, f) => new BlogHandler().Index());
            Routing.AddRoute("paged_index", HttpMethod.Get, new SimplePattern("/blog/{page}").Where("page", GroupMatchType.Integer),
                             (r, f) => new BlogHandler().Index(int.Parse(r["page"])));
            Routing.AddRoute("view", HttpMethod.Get, new SimplePattern("/view/{!dateslug!}").Dateify(), (r, f) => new BlogHandler().View(r.Fill(new BlogRouteModel())));

            Routing.AddRoute("redirect_id", HttpMethod.Get, "/blog/view/{ID}", (r, f) => new BlogHandler().Redirect(r.Fill(new BlogRouteModel())));
            Routing.AddSecureRoute("edit", HttpMethod.Any, new SimplePattern("/edit/{!dateslug!}").Dateify(),
                                   (r, f) => new BlogHandler().Edit(r.Fill(new BlogRouteModel()), f.Fill(new BlogEntryData())));
            Routing.AddSecureRoute("new", HttpMethod.Any, "/new", (r, f) => new BlogHandler().New(f.Fill(new BlogEntryData())));

            //config routes
            Routing.AddRoute("login", HttpMethod.Any, "/login", (r, f) => new ConfigHandler().Login(f.Fill(new LoginModel())));
            Routing.AddRoute("logout", HttpMethod.Get, "/logout", (r, f) => new ConfigHandler().Logout());
            Routing.AddSecureRoute("/config/comments/recalc", (r, f) => new ConfigHandler().RecalculateCommentCounts());
            Routing.AddRoute("/init", (r, f) => new ConfigHandler().Init());
            Routing.AddRoute("/whoami", (r, f) => new ConfigHandler().WhoAmI());
            Routing.AddSecureRoute("/comments/enable", (r, f) => new ConfigHandler().SetComments(true));
            Routing.AddSecureRoute("/comments/disable", (r, f) => new ConfigHandler().SetComments(false));

            //fixed page routes
            Routing.AddRoute("/aboutme", (r, f) => new AboutMeHandler().Get());
            Routing.AddRoute("/projects", (r, f) => new ProjectHandler().Get());

            //comment routes
            Routing.AddRoute("new",
                             HttpMethod.Post,
                             new SimplePattern("/comment/{EntryID}/new"),
                             (r, f) => new CommentHandler().New(r["EntryID"], f.Fill(new CommentData()))
                             );
            Routing.AddSecureRoute("delete", HttpMethod.Post, "/comment/delete/{id}", (r, f) => new CommentHandler().Delete(r["id"]));
            Routing.AddRoute("/comments/list", (r, f) => new CommentHandler().List());

            //tag routes
            Routing.AddSecureRoute("draft tag", HttpMethod.Get,
                                   new SimplePattern("/tags/private-draft/{page}").Where("page", GroupMatchType.Integer),
                                   (r, f) => new TagHandler().Tag("private-draft", int.Parse(r["page"])));
            Routing.AddRoute("tag", HttpMethod.Get,
                             new SimplePattern("/tags/{tag}/{page}").Where("page", GroupMatchType.Integer),
                             (r, f) => new TagHandler().Tag(r["tag"], int.Parse(r["page"])));
            Routing.AddRoute("/tags/{tag}", (r, f) => new TagHandler().RedirectZero(r["tag"]));
            Routing.AddRoute("/tags", (r, f) => new TagHandler().Index());

            //Apparently apache is f*****g retarded so I have to block the directory here
            Routing.AddRoute("f**k it", HttpMethod.Any, "/bin/{*}", (r, f) => { throw new HttpException(401, "denied f****r"); return(null); });

            //Routing.AddRoute("new", HttpMethod.Post, new SimplePattern("/comment/{!dateslug!}/new").Dateify(), (r,f)=>new CommentHandler().
            //Routing.AddSecureRoute("new", HttpMethod.Any, "/new",

            //Routing.AddRoute("view", HttpMethod.Get,

            /*
             * Routing.AddRoute("aboutme","/aboutme",(p) => {return new AboutMeHandler();} );
             * //blog routes
             * Routing.AddRoute("new","/blog/new",(p)=>{return new BlogHandler();});
             * Routing.AddRoute("edit", new SimplePattern("/blog/edit/{id}").Where("id",GroupMatchType.HexString), (p)=>{return new BlogHandler();});
             * Routing.AddRoute("view", new SimplePattern("/blog/view/{id}").Where("id",GroupMatchType.HexString), (p)=>{return new BlogHandler();});
             *
             * Routing.AddRoute("view_new", new SimplePattern("/blog/view/{year}/{month}/{day}/{tiime}").Dateify(), (prop) => {return new BlogHandler();});
             *
             * Routing.AddRoute("delete",new SimplePattern("/blog/delete/{id}").Where("id", GroupMatchType.HexString), (p)=>{return new BlogHandler();});
             * Routing.AddRoute("index","/blog",(p)=>{return new BlogHandler();});
             * Routing.AddRoute("paged_index",new SimplePattern("/blog/{page}").Where("page",GroupMatchType.Integer),(p)=>{return new BlogHandler();});
             * Routing.AddRoute("view","/page/{id}",(p)=>{return new BlogHandler();}); //wtf is this used for?
             *
             * //comment routes
             * Routing.AddRoute("new",new SimplePattern("/blog/{entryid}/comment/add").Where("entryid", GroupMatchType.HexString), (p)=>{return new CommentHandler();});
             * Routing.AddRoute("delete",new SimplePattern("/comments/delete/{commentid}").Where("commentid", GroupMatchType.HexString), (p)=>{return new CommentHandler();});
             * Routing.AddRoute("list","/comments/list",(p)=>{return new CommentHandler();});
             *
             *
             * //config routes
             * Routing.AddRoute("init","/init",(p)=>{return new ConfigHandler();});
             * Routing.AddRoute("login","/login",(p)=>{return new ConfigHandler();});
             * Routing.AddRoute("logout","/logout",(p)=>{return new ConfigHandler();});
             * Routing.AddRoute("whoami","/whoami",(p)=>{return new ConfigHandler();});
             * Routing.AddRoute("enable-comments","/comments/enable",(p)=>{return new ConfigHandler();});
             * Routing.AddRoute("disable-comments","/comments/disable",(p)=>{return new ConfigHandler();});
             *
             * //project routes
             * Routing.AddRoute("projects","/projects",(p)=>{return new ProjectHandler();});
             *
             * //tag routes
             * Routing.AddRoute("index","/tags",(p)=>{return new TagHandler();});
             * Routing.AddRoute("tag",new SimplePattern("/tags/{tag}/{page}").Where("page",GroupMatchType.Integer),(p)=>{return new TagHandler();});
             * Routing.AddRoute("tag_zero","/tags/{tag}",(p)=>{return new TagHandler();});
             */
        }