我正在使用Windows上的Cassandra数据库构建ASP.NET Core MVC应用程序。
我需要帮助用Cassandra实现ASP.NET核心身份。
在Google上,我在版本2.0.0.1中找到public class published_adapter extends BaseAdapter {
Context con;
ArrayList<HashMap<String, String>> class_list;
LayoutInflater inflater;
public class ViewHolder
{
TextView title,description,class_section,date;
ImageButton download;
Button viewasgn;
}
public published_adapter(Context co, ArrayList<HashMap<String, String>> list1) {
class_list = list1;
con = co;
inflater = (LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return class_list.size();
}
@Override
public Object getItem(int arg0) {
return class_list.get(arg0).get("class_name");
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(final int arg0, View arg1, ViewGroup arg2) {
View row = arg1;
ViewHolder holder = new ViewHolder();
if(row == null)
{
row = inflater.inflate(
R.layout.assignment_adapter_layout, arg2, false);
// initialize the elements
holder.download = (ImageButton) row.findViewById(R.id.download);
holder.title = (TextView) row.findViewById(R.id.title);
holder.description = (TextView) row.findViewById(R.id.description);
holder.class_section = (TextView) row.findViewById(R.id.class_section);
holder.date = (TextView) row.findViewById(R.id.date);
holder.viewasgn = (Button) row.findViewById(R.id.attend);
row.setTag(holder);
}
else
{
holder = (ViewHolder)row.getTag();
}
String type = class_list.get(arg0).get("ASSIGNMENT_TYPE");
if (class_list.get(arg0).get("TOTAL_SUBMISSION").equals("0")) {
Log.e("TITLE", class_list.get(arg0).get("TOTAL_SUBMISSION"));
}
else{
Log.e("TITLE", class_list.get(arg0).get("TOTAL_SUBMISSION"));
holder.viewasgn.setVisibility(View.VISIBLE);
holder.viewasgn.setText("VIEW");
}
return row;
}
}
,但它与ASP.NET Core 1.0不兼容。
答案 0 :(得分:3)
我正在研究ASP.NET Core Identity的数据存储适配器 它允许您构建ASP.NET Core Web应用程序,包括成员身份,登录和用户数据。使用此库,您可以在Apache Cassandra上存储用户的成员资格相关数据。
请注意,该库是alpha版本,需要完成
如果您想尝试,请按以下步骤操作:
1 - 从程序包管理器控制台运行以下命令以安装Cassandra身份提供程序。
Install-Package AspNetCore.Identity.Cassandra -Version 1.0.0-alpha1
2 - 将设置添加到 appsettings.json
{
"CassandraNodes": [
"127.0.0.1"
],
"CassandraOptions": {
"KeyspaceName": "identity",
"Replication": {
"class": "NetworkTopologyStrategy",
"datacenter1": "1"
}
}
}
3 - 在 Startup.cs
中配置服务public void ConfigureServices(IServiceCollection services)
{
// CassandraOptions configuration
services.Configure<CassandraOptions>(Configuration.GetSection("CassandraOptions"));
// Cassandra ISession initialization
services.AddCassandraSession<Cassandra.ISession>(() =>
{
var cluster = Cassandra.Cluster.Builder()
.AddContactPoints(Configuration.GetSection("CassandraNodes").GetChildren().Select(x => x.Value))
.Build();
var session = cluster.Connect();
return session;
});
// Added custom Cassandra stores
services.AddIdentity<ApplicationUser, ApplicationRole>()
.UseCassandraStores<Cassandra.ISession>()
.AddDefaultTokenProviders();
// Other code omitted
}
4 - 最后在 Program.cs
中初始化数据库public static class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build()
.InitializeIdentityDb<ApplicationUser, ApplicationRole>();
}
有关更多信息,请在github上查看project site。
答案 1 :(得分:0)
几个选项