如何添加ASP.NET成员资格提供一个空MVC 4项目模板? [英] How to add ASP.NET Membership Provider in a Empty MVC 4 Project Template?

查看:97
本文介绍了如何添加ASP.NET成员资格提供一个空MVC 4项目模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET MVC4新。我创建一个空MVC4项目模板,并尝试添加ASP.NET成员资格提供了进去,但我不理解我怎么能做到这一点。我正在寻找在谷歌,但所有的演示使用Internet应用程序项目模板。

我知道这个问题是不是很好,但我已经花两天时间吧。

请给一些建议或教程用于这一目的。

更新

据尼西姆Razon`s意见,我复制和粘贴窗体身份验证章节,我从MVC4 Web应用程序(互联网应用程序模板)空项目。但是,现在我得到一个异常的要调用这个方法,Membership.Provider属性必须是一个ExtendedMembershipProvider的实例。

  [InitializeSimpleMembership]
公共类HomeController的:控制器
{    公众的ActionResult指数()
    {
        WebSecurity.CreateUserAndAccount(名,密码); //异常是从那里扔。
        返回查看();
    }}

我还增加了以下指令在Web.config文件中:

 <添加键=enableSimpleMembershipVALUE =真/>


解决方案

安装它

您需要添加以下的NuGet包:

添加一个引用到


  • System.Transactions的

测试它

现在,为了测试它,添加以下web.config文件(在的System.Web

 <身份验证模式=表格>
  <形式loginUrl =〜/帐号/登录超时=2880/>
< /认证>

添加下面的连接字符串

 <&是connectionStrings GT;
    <添加名称=DefaultConnection的connectionString =数据源=(的LocalDB)\\ V11.0;初始目录= ASPNET-UnitTestQueries.UI-20121105001038;集成安全性= SSPI; AttachDBFilename = | DataDirectory目录| \\ ASPNET,UnitTestQueries.UI- 20121105001038.mdf的providerName =System.Data.SqlClient的/>
  < /&是connectionStrings GT;

和我所做的就是给控制器,模型,过滤器和视图从互联网模板复制,只是修改了一样东西命名空间,等等,直到你得到它启动和运行

这是结果(无伴奏)


  

登录之前



  

注册



  

登录


I am new in ASP.NET MVC4. I am creating a Empty MVC4 Project Template and trying to add ASP.NET Membership Provider into it but i am not understanding how can I do it. I am searching in Google but all demos are using Internet Application project template.

I know this question is not good but i am already spend two days for it.

Please give a some advice or tutorial for this purpose.

Update

According to Nesim Razon`s advice i copy and paste forms authentication sections to my empty project from a MVC4 Web Application (Internet Application template). But now i get an exception To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".

[InitializeSimpleMembership]
public class HomeController : Controller
{

    public ActionResult Index()
    {
        WebSecurity.CreateUserAndAccount("Name", "Password"); // Exception is thrown from there.
        return View();
    }

}

I am also added the following directive in the Web.config file:

<add key="enableSimpleMembership" value="true" /> 

解决方案

Installing it

You need to add the following Nuget Packages:

Add a reference to

  • System.Transactions

Testing it

Now in order to test it, add the following to the web.config file (Under system.web):

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>

Add the following connection string

  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-UnitTestQueries.UI-20121105001038;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-UnitTestQueries.UI-20121105001038.mdf" providerName="System.Data.SqlClient" />
  </connectionStrings>

And what I did was to copy the controllers, models, filters and views from the Internet template and just modify things like the namespace and so on until you get it up and running

This is the result (without styles)

Before login

Registering

Logged IN

这篇关于如何添加ASP.NET成员资格提供一个空MVC 4项目模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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