目录:
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
浙公网安备 33010602011771号