简单的ASP.NET成员资格提供? [英] ASP.NET simple membership provider?

查看:134
本文介绍了简单的ASP.NET成员资格提供?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打开Asp.Net 4的mvc应用互联网。模板。我设置连接字符串,我的数据库是这样的:

I opened Asp.Net Mvc 4 Internet App. template. And I set connection string for my database like this:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=ALI-PC\;Initial Catalog=OsosPlusDb;Persist Security Info=True;User ID=sa;Password=sa;" providerName="System.Data.SqlClient" />
</connectionStrings>

我跑项目,点击注册按钮。我创建了这样一个新的用户:

I run project, click register button. I created a new user like this:

当我点击注册后,我得到这个错误:

When I click register to post I get this error:

但它会在DB一个新用户并不会创建membership_user(会员表不含有添加的用户信息):

But it creates a new user in DB and it does not create membership_user (Membership table is not contain added user info):

我不能发现有什么问题。有时候没有出现错误。

I cant find What is the problem. Sometimes there is no error occured.

更新

和异常快照:

AcoountModel:

AcoountModel:

public class UsersContext : DbContext
{
    public UsersContext()
        : base("DefaultConnection")
    {
    }

    public DbSet<UserProfile> UserProfiles { get; set; }
}

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public string UserName { get; set; }
}

InitializeSimpleMembershipAttribute.cs

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute
{
    private static SimpleMembershipInitializer _initializer;
    private static object _initializerLock = new object();
    private static bool _isInitialized;

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        // Ensure ASP.NET Simple Membership is initialized only once per app start
        LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);
    }

    private class SimpleMembershipInitializer
    {
        public SimpleMembershipInitializer()
        {
            Database.SetInitializer<UsersContext>(null);

            try
            {
                using (var context = new UsersContext())
                {
                    if (!context.Database.Exists())
                    {
                        // Create the SimpleMembership database without Entity Framework migration schema
                        ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                    }
                }

                WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
            }
        }
    }
}

LAST编辑和摘要

问题是字符(I)。如果我不使用I一切都还好。但是当我用它我得到的错误。我怎样才能解决这个问题。

Problem is character ("i"). If I dont use "i" everything is okay. But When I use it I got that error. How Can I fix this problem.

推荐答案

手动创建数据库(不要让你的项目全自动创建数据库)
当你创建选项下的数据库设置排序规则以Latin1_General_CI_AS ..

Create your database manually (dont allow your project create your database automaticly) and when your create your database set collation to Latin1_General_CI_AS under Options..

如果您在数据库上使用土耳其语字符数据库归类在要Turkish_CI_AS,你可以改变你的列排序规则.. 按照以下步骤..

If you use Turkish character on your database your database collation has to be Turkish_CI_AS and you can change your column collation.. Follow the steps..

PS:整理约为如果你用土耳其语字符排序,如果你想有点像A,B,C,C,D,E,F,G,H,I,I ..你的数据库归类已成为土耳其..)

(P.S.: Collation is about sorting if you use Turkish character and if you want to sort like a,b,c,ç,d,e,f,g,h,ı,i,.. your database collation has to be Turkish..)

1)右键单击username列,然后单击修改。

1) Right click UserName Column and click Modify..

2)点击整理。

3),选择Latin1_General。

3) And select Latin1_General..

点击确定并保存更改。

这篇关于简单的ASP.NET成员资格提供?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆