我创建了一个基于角色的菜单,我按照本教程进行了操作.在该页面的某些位置,您将看到以下代码行:
String[] roles = Roles.GetRolesForUser();
Run Code Online (Sandbox Code Playgroud)
它返回当前登录用户的所有角色.我想知道如何使用新的ASP.NET身份系统实现这一目标?
它仍然是新的,没有太多可以找到它.
如何ListBoxFor在可能有多个选项的地方枚举枚举?
例如enum,包含角色:
public enum RoleType
{
[Display(Description = "Administrator", ResourceType = typeof(Resource))]
Administrator = 1,
[Display(Description = "Moderator", ResourceType = typeof(Resource))]
Moderator = 2,
[Display(Description = "Webmaster", ResourceType = typeof(Resource))]
Webmaster = 3,
[Display(Description = "Guest", ResourceType = typeof(Resource))]
Guest = 4,
Etc.... = 5,
}
Run Code Online (Sandbox Code Playgroud)
我已经看到用dropdownlist/ 完成了这个selectlists.但是有没有办法为多选列表执行此操作?
[编辑]
这就是我想要使用它的方式,它现在是如何工作的,但不会用其他语言翻译:
var roles = from role r in Enum.GetValues(typeof(RoleType))
select new
{
Id = (int)Enum.Parse(typeof(RoleType), r.ToString()),
Name = r.ToString()
};
searchModel.roles = new …Run Code Online (Sandbox Code Playgroud) 如何在Azure表存储上设置多个过滤器?
这就是我尝试过的:
string partitionFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "partition1");
string date1 = TableQuery.GenerateFilterCondition("Date", QueryComparisons.GreaterThanOrEqual, "31-8-2013T14:15:14Z");
string date2 = TableQuery.GenerateFilterCondition("Date", QueryComparisons.LessThanOrEqual, "31-8-2013T14:15:14Z");
string finalFilter = TableQuery.CombineFilters(partitionFilter, TableOperators.And, date1);
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为TableQuery.CombineFilters()只需要3个参数.我需要第二个日期的额外参数.
我的第二次尝试:
string filter = "PartitionKey eq 'partition1' and Date ge datetime'31-8-2013T14:15:14Z' and Date lt datetime'31-8-2013T14:19:10Z'";
TableQuery<CustomEntity> query = new TableQuery<CustomEntity>().Where(filter).Take(5);
Run Code Online (Sandbox Code Playgroud)
这回来了400 bad request.但是如果我删除了'datetime'它会运行但是返回没有结果,而它应该返回几个100条记录.
根据msdn的这个文档,这就是应该如何格式化日期时间.
我的结果应该是两个日期之间的所有记录.
我怎样才能做到这一点?
经过大量阅读并尝试使用Entity Framework最新的稳定版本(6.1.1).
我读了大量关于是否要使用存储库与矛盾的EF6或EF一般的,因为它DbContext已经提供了一个资源库和DbSet的UoW,开箱即用.
让我首先解释一下我的解决方案在项目方面所包含的内容,然后我将回到这个矛盾中.
它有一个类库项目和一个asp.net-mvc项目.类lib项目是数据访问和Migrations启用的位置Code First.
在我的类lib项目中,我有一个通用的存储库:
public interface IRepository<TEntity> where TEntity : class
{
IEnumerable<TEntity> Get();
TEntity GetByID(object id);
void Insert(TEntity entity);
void Delete(object id);
void Update(TEntity entityToUpdate);
}
Run Code Online (Sandbox Code Playgroud)
以下是它的实现:
public class Repository<TEntity> where TEntity : class
{
internal ApplicationDbContext context;
internal DbSet<TEntity> dbSet;
public Repository(ApplicationDbContext context)
{
this.context = context;
this.dbSet = context.Set<TEntity>();
}
public virtual IEnumerable<TEntity> Get()
{
IQueryable<TEntity> …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc dependency-injection ef-code-first entity-framework-6
如果夏令时生效,并且日期对象已保存到数据库中(UTC格式),您将检索该数据库以在视图中显示它(例如视图中asp.net-mvc).
您可以使用此方法执行此操作:
public static DateTime ConvertToLocalTimeFromUtcTime(DateTime utcDate, string timeZoneId)
{
TimeZoneInfo localZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(utcDate, localZone);
if (localZone.IsDaylightSavingTime(localTime))
localTime = localTime.AddHours(1); // is this needed !?
return localTime;
}
Run Code Online (Sandbox Code Playgroud)
问题是,是否TimeZoneInfo.ConvertTimeFromUtc()处理DST或您是否必须自己检查并在日期对象中添加或减去X小时?
通过将日期对象转换为UTC格式来将日期对象持久化到数据库时的相同问题ToUniversalTime().
如何将AspNetUser表的PK列从a guid更改为int数据类型?现在应该可以使用asp.net-identity今天发布的最新版本.
但我无法在任何地方找到这样做的方法?
我正试图POST从一个controller到另一个controller.两者controller都来自不同的项目.一个项目用于模拟表示层(我将在此处调用测试项目).
从测试项目我试图将2个简单string参数传递给另一个控制器,我将称之为进程.
var values = new List<KeyValuePair<string, string>>();
values.Add(new KeyValuePair<string, string>("id", param.Id.Value));
values.Add(new KeyValuePair<string, string>("type", param.Type.Value));
var content = new FormUrlEncodedContent(values);
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("nl-NL"));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string token = param.token.Value;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var response = client.PostAsync("/api/Process/Product", content).Result;
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsStringAsync().Result;
return Request.CreateResponse(HttpStatusCode.OK, result);
}
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "fail");
}
Run Code Online (Sandbox Code Playgroud)
在进程控制器中,我试图像这样接收它:
[HttpPost]
public HttpResponseMessage …Run Code Online (Sandbox Code Playgroud) 标题基本上总结了它,我想在这里完成的事情.
更多信息,我有一个有4列的表.我需要它的精确副本,但只需要更改一列的值.
假设该列名为客户编号123456(其他值并不重要).
如何复制整个表并将客户编号更改为123457并将该副本插回到同一个表中.
如果一切顺利,我应该有两倍的数据(数据库中只有一个客户)记录,就像之前只有客户编号发生变化的记录一样.
我正在使用MSSQL2008 R2.
我正在使用Tooltip()来自Twitter-Bootstrap.当悬停在元素上时,会tooltip显示出来.但除非你将鼠标移开,否则它会停留在那里.
如何在弹出几秒钟后让它消失,而不是等到鼠标离开元素?