所以我对Web API是全新的,我想我会开始一个测试项目来学习它和AngularJS以及它们如何很好地协同工作......等等.
我在我的解决方案中创建了一个多层架构,在我的TPlan.API项目中,我有以下配置的路由Global.asax
GlobalConfiguration.Configuration.Routes.Add("default",
new HttpRoute("api/{controller}"));
Run Code Online (Sandbox Code Playgroud)

TPlan.WEB是我的MVC应用程序,它被设置为"启动项目".当我运行它时,我希望能够:
mysite的:端口/ API /测试
并从我的测试控制器中获取API的值.
但是它对我不起作用,我得到以下结果:
没有找到与请求URI"mysite:port/api/test"匹配的HTTP资源.
我想做这样的事情:
public class TrackerContext : DbContext
{
public bool TrackNewValues { get; set; }
public TrackerContext(bool trackNewValues = false)
: base()
{
TrackNewValues = trackNewValues;
}
public TrackerContext(string connectinString, bool trackNewValues = false)
: base(connectinString)
{
TrackNewValues = trackNewValues;
}
public DbSet<AuditLog<string>> AuditLog { get; set; }
public DbSet<AuditLogChild> LogChildren { get; set; }
}
public class AuditLog<UserIdOrUserNameColumnType>
{
public AuditLog()
{
Children = new List<AuditLogChild>();
}
[Key]
public Guid AuditLogID { get; set; }
public UserIdOrUserNameColumnType UserId { get; …Run Code Online (Sandbox Code Playgroud) 我想更改ASP.NET Identity 2.0使用的表的名称.我见过各种类似的问题,但没有解决我的问题.例如,这种类型的解决方案:http: //www.goatly.net/customizing-table-names-for-identitydbcontextwithcustomuser-data-contexts 似乎依赖于Code First(?).无论如何,实现OnModelCreating对我没有任何帮助.我基本上将AspNetUsers和类似的表重命名为我自己的名字,并希望能够使用它们.我有一个我想要使用的现有EF上下文(MyContext),所以我将其修改为从IdentityDbContext派生(编辑t4模板),然后在Startup.Auth中我有:
UserManagerFactory = () =>
{
var context = new MyContext();
Database.SetInitializer<MyContext>(new IdentityDbInitializer());
var userStore = new UserStore<IdentityUser>(context){
DisposeContext = true
};
return new UserManager<IdentityUser>(userStore);
};
Run Code Online (Sandbox Code Playgroud)
但是当我尝试登录时出现问题,我得到"无法联系服务器".我想这是因为我的UserStore无法知道我的上下文中的User表.我希望这是OnModelCreating代码可以做的,但我对此很朦胧.我想UserStore仍然在寻找一个"AspNetUsers"表,虽然我不知道这些名字的来源.我也很难为我的上下文修改t4模板 - 这是我应该从IdentityDbContext派生的方式吗?
任何帮助非常感谢.
我想在我的TT中的CS文件中使用我自己的类定义.
例:
public class ClassDefinition
{
public string NameSpace { get; set; }
public string Name { get; set; }
public string Protection { get; set; }
List<ClassProperty> Properties { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的TT看起来像:
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml"#>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ include file="$(ProjectDir)ClassDefinition.cs" #> …Run Code Online (Sandbox Code Playgroud) 我已将ApplicationUserClass 和Last名称添加到Class中.
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
public string FirstName { get; set; }
public string LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
还添加了信息 RegisterViewModel
我的应用程序成功创建了First和LastName表,但是我无法获得在_LoginPartial "User.Identity.Name"中显示的名字和姓氏
我需要加密许多数据库列(在Sql Server 2012中).已经决定我们应该使用列级加密(在sql server中实现).在应用程序方面,我将在一些复杂的域模型之上构建一个web api.我真的想利用Entity Framework的代码第一种方法来维护一个干净的域模型.有没有人在这里有一个可行的解决方案,不涉及诉诸存储过程?理想情况下,我想以某种方式操纵实体框架生成的sql来包装某些字段来执行sql加密/解密功能.
理想情况下,例如:
modelBuilder.Entity<MyTable>().ToTable("Table1").Property(p => p.SensativeData).encrypt("keyName",authenticatorFunc);
Run Code Online (Sandbox Code Playgroud) 让我们从一个简单的视图模型开始:
public class MyViewModel
{
public string Value { get; set; }
public IEnumerable<SelectListItem> Values { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
下拉列表可能如下所示:
@Html.DropDownListFor(m => m.Value, Model.Values)
Run Code Online (Sandbox Code Playgroud)
但是,因为下拉列表需要两个值,所以不能使用它:
public class MyViewModel
{
[UIHint("DropDownList")]
public string Value { get; set; }
public IEnumerable<SelectListItem> Values { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
视图包含:
@Html.EditForModel()
Run Code Online (Sandbox Code Playgroud)
因为下拉知道源代码没有固有的方法,直到你从UIHint中驱逐:
public DropDownListAttribute : UIHintAttribute
{
public DropDownListAttribute (string valuesSource)
: base("DropDownList", "MVC")
{
}
}
Run Code Online (Sandbox Code Playgroud)
那么人们可能会喜欢它:
public class MyViewModel
{
[DropDownList("Planets")]
public string PlanetId{ get; set; }
public IEnumerable<SelectListItem> Planets { …Run Code Online (Sandbox Code Playgroud) 我将EF Core和ASP Core 2.0一起使用。使用最新的身份框架。我在“全部”页面上收到此异常。
InvalidOperationException:属性“ User”不是实体类型“ Gallery”的导航属性。“ include(string)”方法只能与“。”一起使用。导航属性名称的分隔列表。
ApplicationUser看起来像:
public class ApplicationUser : IdentityUser<Guid>
{
public ICollection<Gallery> Galleries { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
实体图库如下所示:
public class Gallery
{
public int Id { get; set; }
public Guid UserId { get; set; }
public string Title { get; set; }
public int? ArticleId { get; set; }
public string Photos { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public Article Article …Run Code Online (Sandbox Code Playgroud) 尝试使用API来构建网格.一切都很好,但在最后一排瓷砖之后,页面变成空白,只是保持滚动和滚动......网格就像这样构建:
body: new GridView.builder(
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: (orientation == Orientation.portrait) ? 2 : 3),
itemBuilder: (BuildContext context, int index) {
return new Card(
child: new GridTile(
footer: new Text(data[index]['name']),
child: new Text(data[index]['image']), //just for testing, will fill with image later
),
);
},
)
Run Code Online (Sandbox Code Playgroud)
例外情况是我不断向下滚动空白页面,最后一个数字(包括:24)变大2倍(24,26,28等)的倍数.
I/flutter (11001): Another exception was thrown: RangeError (index): Invalid value: Not in range 0..23, inclusive: 24
Run Code Online (Sandbox Code Playgroud)
有人看过GridView.builder的这种行为吗?
c# ×6
asp.net ×2
asp.net-mvc ×2
asp.net-core ×1
attributes ×1
automapper ×1
azure ×1
css ×1
dart ×1
database ×1
flutter ×1
generics ×1
orm ×1
razor ×1
sql-server ×1
t4 ×1
texttemplate ×1