用Nancy和Simple.Data创建一个图片博客 第三部分:渲染一些Views

Nancy与Simple.Data搭建图片博客
本文介绍如何使用Nancy和Simple.Data框架创建图片博客的第三部分教程,包括实现用户认证模块、改进档案模块及添加首个Razor视图。
目录:
placeholder
前言:
巴拉巴拉巴拉
步骤1:创建一个AuthenticationModule
创建一个新的Module,我们叫它AuthenticationModule:
public class AuthenticationModule : BaseModule
{
    public AuthenticationModule()
        : base()
    {
        Get["/login"] = parameters =>
        {
            return "Display the login form";
        };
        Post["/login"] = parameters =>
        {
            // Perform validation, then redirect
            return Response.AsRedirect("/admin/photos");
        };
        Post["/logout"] = parameters =>
        {
            // Logout and redirect
            return Response.AsRedirect("/login");
        };
    }
} 
 
步骤2:更新AdminModule
我们现在在AuthenticationModule里加进了登录的route,我们可以删除AdminModule里的登录route。我们还要再加进一个route,这个上次没有考虑到。那就是有关删除照片的route。代码如下:
步骤3:改进ArchivesModule
  TheCodeJunkie ( @TheCodeJunkie on Twitter),Nancy的主要作者,建议在route定义中使用正则表达式。也就是:
public class ArchivesModule : BaseModule
{
    public ArchivesModule()
        : base("/archives")
    {
        Get[""] = parameters =>
        {
            return "????";
        };
        Get[@"/(?<year>19[0-9]{2}|2[0-9]{3})"] = parameters 
        =>
        {
            return String.Format("All photo's of the year {0}
            ", parameters.year);
        };
        Get[@"/(?<year>19[0-9]{2}|2[0-9]{3})/(?<month>0[1-9]
        |1[012])"] = parameters =>
        {
            return String.Format("All photo's of month {0} 
            of the year {1}", parameters.month, parameters.
            year);
        };
    }
} 
步骤3:添加第一个Razor View


posted on 2012-04-27 00:04 pieux 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/pieux/archive/2012/04/27/2472849.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值