您的位置:首页 > 其它

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

2012-04-27 00:04 267 查看
目录: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

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐