zoukankan      html  css  js  c++  java
  • 实现 Profile Provider in ASP.NET MVC

    asp.net mvc 没有向之前那样自动为我们生成可以直接操作profile的ProfileCommon类,所以我们要自己写一个。

    当然这还是比较容易的。

    ProfileController.cs

    [AcceptVerbs("POST")]
    public ActionResult CreateProfile(string company, string phone, string fax, string city, string state, string zip)
    {
    MembershipUser user = Membership.GetUser();
    ProfileCommon profile = ProfileCommon.Create(user.UserName, user.IsApproved) as ProfileCommon;

    profile.Company = company;
    profile.Phone = phone;
    profile.Fax = fax;
    profile.City = city;
    profile.State = state;
    profile.Zip = zip;
    profile.Save();

    return RedirectToAction("Index", "Account");
    }

    web.config:
    这里需要注意的是,需要去除掉自定义在<properties>中的所有属性,因为我们在之后的ProfileCommon里自定义了相应的属性。
    同时在<profile>中添加

    <profile inherits="ProfileExample.Models.ProfileCommon" defaultProvider="AspNetSqlProfileProvider">

     

    实现的ProfileCommon类

    public class ProfileCommon : ProfileBase
    {
    public virtual string Company
    {
    get
    {
    return ((string)(this.GetPropertyValue("Company")));
    }
    set
    {
    this.SetPropertyValue("Company", value);
    }
    }

    public virtual string Phone
    {
    get
    {
    return ((string)(this.GetPropertyValue("Phone")));
    }
    set
    {
    this.SetPropertyValue("Phone", value);
    }
    }

    public virtual string Fax
    {
    get
    {
    return ((string)(this.GetPropertyValue("Fax")));
    }
    set
    {
    this.SetPropertyValue("Fax", value);
    }
    }

    public virtual string City
    {
    get
    {
    return ((string)(this.GetPropertyValue("City")));
    }
    set
    {
    this.SetPropertyValue("City", value);
    }
    }

    public virtual string State
    {
    get
    {
    return ((string)(this.GetPropertyValue("State")));
    }
    set
    {
    this.SetPropertyValue("State", value);
    }
    }

    public virtual string Zip
    {
    get
    {
    return ((string)(this.GetPropertyValue("Zip")));
    }
    set
    {
    this.SetPropertyValue("Zip", value);
    }
    }

    public virtual ProfileCommon GetProfile(string username)
    {
    return Create(username) as ProfileCommon;
    }
    }

     

    转自http://kogeiman.ixiezi.com/2011/01/13/%E5%AE%9E%E7%8E%B0-profile-provider-in-asp-net-mvc/

  • 相关阅读:
    IO基础
    集合框架
    数据结构基础
    进程和线程
    matlab绘制三维图形
    matlab figure 窗口最大化
    Matlab中的fread函数
    matlab中fopen 和 fprintf函数总结
    matlab中findstr,strfind,strcmp,strncmp区别与联系
    matlab取消和添加注释以及一些快捷键
  • 原文地址:https://www.cnblogs.com/Dtscal/p/2709477.html
Copyright © 2011-2022 走看看