我正在使用ninject作为我的IoC,我编写了一个角色提供程序,如下所示:
public class BasicRoleProvider : RoleProvider
{
private IAuthenticationService authenticationService;
public BasicRoleProvider(IAuthenticationService authenticationService)
{
if (authenticationService == null) throw new ArgumentNullException("authenticationService");
this.authenticationService = authenticationService;
}
/* Other methods here */
}
Run Code Online (Sandbox Code Playgroud)
我读到Provider在ninject注入实例之前,类被实例化了.我该如何解决这个问题?我目前有这个ninject代码:
Bind<RoleProvider>().To<BasicRoleProvider>().InRequestScope();
Run Code Online (Sandbox Code Playgroud)
从这个答案在这里.
If you mark your dependencies with [Inject] for your properties in your provider class, you can call kernel.Inject(MemberShip.Provider) - this will assign all dependencies to your properties.
我不明白.
我读了EditorTemplates自动加载,但是从asp.net的MVC 2和3,现在用剃刀,我仍然无法得到这个工作.
我的模型看起来像这样:
public class RoleViewModel
{
public int RoleId { get; set; }
public bool InRole { get; set; }
public string RoleName { get; set; }
}
public class UserViewModel
{
public User User { get; set; }
public IEnumerable<RoleViewModel> Roles { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的观点如下:
〜/查看/角色/ Edit.cshtml
@model Project.Web.ViewModel.UserViewModel
@using (Html.BeginForm()) {
@Html.EditorFor(model => model.Roles)
<!-- Other stuff here -->
}
Run Code Online (Sandbox Code Playgroud)
〜/查看/角色/ EditorTemplates/RoleViewModel.cshtml
@model Project.Web.ViewModel.RoleViewModel
@foreach (var i in Model)
{
<div>
@i.RoleName
@Html.HiddenFor(model => i.RoleId) …Run Code Online (Sandbox Code Playgroud) 我坚持使用本教程来创建一个多项目的可视化工作室模板.我特意坚持这一行:
Select the files and folders to include in your template, right-click the selection, click Send To, and then click Compressed (zipped) Folder. The files and folders are compressed into a .zip file.
我做了以下步骤:
.zip文件中.我该怎么办?
我的意图是:制作解决方案文件夹,其中包括一些dll(DI,单元测试框架等).有这些dlls参考.其他项目中的参考项目.重命名部分项目.例如.进行替换的能力{MyProj}.Service与NewName.Service
我在SQL Server 2008 r2中有用户表.什么都没有加密,但我想至少加密密码,直到应用程序准备好,将更好地处理这个.我可以这样做吗?手动使密码加密.
我想创建一个名称列表并将其作为强类型枚举访问.例如.
string foo = FileName.Hello; //Returns "Hello.txt"
string foo1 = FileName.Bye; //Returns "GoodBye.doc"
Run Code Online (Sandbox Code Playgroud)
或者它可能是一个像这样的对象:
Person p = PeopleList.Bill; //p.FirstName = "Bill", p.LastName = "Jobs"
Run Code Online (Sandbox Code Playgroud)
如何创建这样的数据类型?
我不知道关键字是什么,所以这里是我想要的一个例子:
return from i in userRepo.GetUsers()
select new SimpleUser{
i.UserId,
i.Name
};
Run Code Online (Sandbox Code Playgroud)
userRepo.GetUsers()返回类型IQueryable<User>.我想将其转换IQueryable<SimpleUser>为我可以限制对User域的某些属性的访问.
如果不对此类翻译进行硬编码,我该怎么做?那些像automapper或ValueInjecter这样的工具怎么样呢?
此外,这项技术叫做什么?
有一种简单的方法可以在asp.net mvc应用程序中存储用户设置吗?例如,设置,例如他们想要通知的频率,发送通知的位置以及您可以想到的用户将为自己个性化的任何其他内容.
在.net中有一些内置的东西可以做到吗?我想使用链接到该用户的foriegn密钥将设置存储在数据库中.
如果没有内置的.net功能,我将如何设计我的数据库表进行设置?(只是一个例子)
所以默认的MVC应用程序有以下css(在Site.css中) -
/* Styles for editor and display helpers
----------------------------------------------------------*/
.display-label,
.editor-label
{
margin: 1em 0 0 0;
}
.display-field,
.editor-field
{
margin:0.5em 0 0 0;
}
.text-box
{
width: 30em;
}
.text-box.multi-line
{
height: 6.5em;
}
.tri-state
{
width: 6em;
}
Run Code Online (Sandbox Code Playgroud)
需要进行哪些更改?谢谢
我正在关注此页面上的ninject过滤器属性设置.
对他们来说,他们有:
.WithConstructorArgumentFromControllerAttribute<LogAttribute>(
"logLevel", attribute => attribute.LogLevel);
Run Code Online (Sandbox Code Playgroud)
第二个参数是期待a Func<LogAttribute, object> callback.他们的实际参数列表设置如下:
Log(LogLevel = Level.Debug)
Run Code Online (Sandbox Code Playgroud)
但我的filter属性设置如下:
public class AuthAttribute : FilterAttribute { }
public class AuthFilter : IAuthorizationFilter
{
private readonly IUserService userService;
private string[] roles;
//Stuck on the constructor also. How do I accept params?
public AuthFilter(IUserService userService, params string[] roles)
{
this.userService = userService;
this.roles = roles;
}
public void OnAuthorization(AuthorizationContext filterContext)
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
不知怎的,这是错误的.因为我希望我的过滤器看起来像:
[Auth("Admin", "Contrib")]
Run Code Online (Sandbox Code Playgroud)
我的绑定:
kernel.BindFilter<AuthFilter>(FilterScope.Controller, 0)
.WhenControllerHas<AuthAttribute>()
.WithConstructorArgumentFromControllerAttribute<AuthAttribute>("roles", …Run Code Online (Sandbox Code Playgroud) 我正在asp.net mvc中构建一个REST API.我的系统使用表单身份验证 用户名/密码或openId/fbconnect等.如果我有[Authorize]动作的属性,Android应用程序或桌面应用程序将如何访问该方法?
或者更好的问题是,我如何设计桌面应用程序进行身份验证?我是否需要传递API密钥或某种某种令牌?或者桌面应用程序是否像浏览器一样使用内部cookie?我不太确定RESTful API如何在具有身份验证的Web浏览器之外工作.