- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试遵循Nancy.Demo.Authentication.Forms示例,但我遇到了问题,因为示例代码看起来已经过时了。如果这个问题很长,我很抱歉,但我不想错过我的错误。这是我到目前为止所做的:
我通过包管理器控制台(VS11 beta)成功安装了身份验证包
PM> install-package nancy.Authentication.Forms
Attempting to resolve dependency 'Nancy (= 0.10.0)'.
Successfully installed 'Nancy.Authentication.Forms 0.10.0'.
Successfully added 'Nancy.Authentication.Forms 0.10.0' to uMentor.
我编写了 IUserMapper 的实现,它依赖于我的 RavenDB session 提供程序并使用它来查找和验证用户
public class FormsAuthenticationService : IUserMapper
{
private readonly IRavenSessionProvider _ravenSessionProvider;
public FormsAuthenticationService(IRavenSessionProvider ravenSessionProvider)
{
_ravenSessionProvider = ravenSessionProvider;
}
public IUserIdentity GetUserFromIdentifier(Guid identifier)
{
using (var ravenDB = _ravenSessionProvider.GetSession())
{
var user = ravenDB.Query<User>().FirstOrDefault(u => u.FormsAuthenticationGuid == identifier);
return user;
}
}
public static Guid? ValidateUser(IDocumentSession ravenDB, string username, string password)
{
var user = ravenDB.Query<User>().FirstOrDefault(u => u.UserName == username && u.Password == password);
if (user == null)
{
return null;
}
return user.FormsAuthenticationGuid;
}
}
我已经在我的 User 类中添加了一个属性,以满足使 cookie 更安全所需的 Guid 标识符字段(我已阅读 grumpydev 的帖子并理解为什么需要这个 Guid,但是将其作为一个属性是一个好的做法吗? User 类中的字段?)
public class User : IUserIdentity
{
public string UserName { get; set; }
public IEnumerable<string> Claims { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public Guid FormsAuthenticationGuid { get; set; }
}
最后,我通过直接从演示中窃取代码(上面的链接)为我的 Bootstrap 添加了更多设置。这就是我遇到问题的地方。代码似乎已更改。
public class MyBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context)
{
base.ConfigureRequestContainer(container, context);
container.Register<IUserMapper, FormsAuthenticationService>();
}
protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines, NancyContext context)
{
var formsAuthConfiguration =
new FormsAuthenticationConfiguration()
{
//These properties do not exist! <<---- Edit - yes they do - see comment
RedirectUrl = "~/login",
UserMapper = requestContainer.Resolve<IUserMapper>(),
};
//This method does not exist <<---- Edit - yes they do - see comment
FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
}
protected override NancyInternalConfiguration InternalConfiguration
{
get { return NancyInternalConfiguration.WithOverrides(x => x.NancyModuleBuilder = typeof(RavenAwareModuleBuilder)); }
}
}
编辑 1事实证明我的错误是愚蠢的(不正确的 using
语句 - 请参阅下面的评论)。上面的所有代码现在都可以正常工作,所以我将保留这个问题。
最佳答案
以防万一您错过了上面的评论,答案非常简单:
Gotcha! OK, I found the problem with the broken code. Resharper helpfully put in the following using statement: 'using FormsAuthenticationConfiguration = System.Web.Configuration.FormsAuthenticationConfiguration;'. Removing this solved the broken code :-) However I would still welcome any comments about my implementation. I need reassurance that I am on the right path.
关于forms-authentication - Nancy:FormsAuthentication - 入门,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10189711/
我希望通过 2 个或更多路由模式执行相同的操作。 例如: //Route 1: Get["/{category}/{product_name}/{id}"] // Route 2: Get["/api
我正在开发一个使用 WPF 应用程序中托管的 Nancy 的小项目。我希望能够远程下载 ~8MB 的 PDF 文件。我能够让下载工作,但在下载过程中,应用程序不会响应任何其他请求。有没有一种方法可以允
我正在使用 Nancy 通过 Web 服务实现 API。 我想要一个/help 或/docs 页面以编程方式列出所有可用路由,以便我可以为 API 用户提供自动生成/更新的文档。 关于如何做到这一点的
有没有办法为 Nancy 服务自动生成 Swagger 文档(或类似文档)? 我找到了Nancy.Swagger ,但是没有关于如何使用它的信息,并且演示应用程序似乎没有演示生成文档(如果有,它并不明
我看过这个帖子:Nancy: how do I capture all requests irrespective of verb or path并关注了 github 文章。 但它不起作用。我只是在
我在 Nancy 中提供静态内容(例如 JavaScript)时遇到问题。 例如使用 self hosting sample我在 Views 文件夹中添加了一个 test.js 并添加了一个 标记到
我是 Nancy 的新手,我想返回自定义 HttpStatusCode 和正文(内容)。如果我返回 HttpStatusCode,它会返回一个空白正文。如果我返回一个字符串,那么它会返回该字符串作为正
我正在创建一个 Nancy 模块,该模块最终将托管在 Windows 服务内。我目前正在 WPF 测试应用程序中运行它。要启动 Nancy 托管,我使用 Nancy.Hosting.Self 并调用:
我不知道如何使用 Super Simple View Engine 预选下拉菜单。 我的模型有一个属性datatype,它是一个数字,我想在下拉列表中预先选择它。 正如我从文档中看到的那样,条件语句仅
我想在每个请求中做一些事情,无论是模块还是路由。我如何在 Nancy 2.x 中完成此操作? 如果找到How to Intercept all Nancy requests和 How do I cap
得知 Nancy 有自己的 razor 实现时,我有点吃惊,它的行为可能像也可能不像 razor。在实践中,这会导致问题吗?什么是“大多数人”用于 Nancy View 引擎的?为什么没有使用真正的
在使用 Nancy FX 时,我遇到了以下异常,该异常是在尝试启动 Web 服务时引发的:AutomaticUrlReservationCreationFailureException 更详细地研究后
我正在尝试运行一个自托管的 Nancy 应用程序,但我无法让它返回有效响应。我是南希的新人;我希望我的问题是相当简单的。 这是一些代码: class Program { static void
我想要在初始匹配后匹配/捕获所有 url 段的 nancy 规则。 例如,我想这样做: 有一个网址,如:/views/viewname/pageid/visitid/someother 和这样的规则:
我们通过 NuGet 将 Nancy 从 v1.2.0 更新到 1.3.0。根据changelog似乎没有与我们的应用程序相关的重大更改。但是我们现在收到运行时错误 Method not found:
我在工作中使用 topShelf (Windows 7) 编写了一个 Nancy 自托管服务,它工作得很好。我把它带回家并在 Windows 10 下运行它,但出现以下错误: Nancy 自身主机无法
我已经阅读了很多 Jabbr代码来学习 Nancy 并尝试在我自己的应用程序中实现许多相同的模式。我似乎无法开始工作的一件事是应用程序启动类的概念。 Jabbr 代码库有一个 App_Start带有
我需要重定向到当前模块下的路径: modulePath = "/test"; Get["/there"] = ... Get["/here"] = routeParams => { return
我已经设置了一个 Nancy bootstrap 来从非默认目录路径(它是自托管的 Nancy)提供静态内容。 奇怪的是,以下内容适用于自定义 View 位置约定,但不适用于 js 或 css 静态内
我正在拼凑一个基于 Nancy.Demo.Authentication.Forms 的演示应用程序. 我正在实现 Claims和 UserName在我的UserIdentity:IUserIdenti
我是一名优秀的程序员,十分优秀!