相关疑难解决方法(0)

如何分配配置文件值?

我不知道我缺少什么,但我在Web.config文件中添加了配置文件属性,但无法访问配置文件.代码中的项目或创建新的配置文件.

asp.net profile asp.net-mvc asp.net-membership

110
推荐指数
4
解决办法
6万
查看次数

在ASP.NET MVC中实现Profile Provider

对于我的生活,我无法让SqlProfileProvider在我正在进行的MVC项目中工作.

我意识到的第一个有趣的事情是Visual Studio不会自动为您生成ProfileCommon代理类.这不是什么大问题,因为扩展ProfileBase类只是简单的事情.在创建了ProfileCommon类之后,我编写了以下用于创建用户配置文件的Action方法.

[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"); 
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是对ProfileCommon.Create()的调用无法转换为类型ProfileCommon,因此我无法取回我的配置文件对象,这显然导致下一行失败,因为配置文件为空.

以下是我的web.config的片段:

<profile defaultProvider="AspNetSqlProfileProvider" automaticSaveEnabled="false" enabled="true">
    <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="/" />
    </providers>
    <properties>
        <add name="FirstName" type="string" />
        <add name="LastName" type="string" …
Run Code Online (Sandbox Code Playgroud)

provider profile asp.net-mvc

63
推荐指数
3
解决办法
4万
查看次数

在ASP.NET MVC中实现自定义配置文件提供程序

我尝试了很多在ASP.NET MVC中实现自定义配置文件提供程序.我已经阅读了很多很多教程,但我无法找到问题所在.它与ASP.NET MVC中的实现配置文件提供程序非常相似.

但是我想创建自己的Profile Provider,所以我编写了以下继承自的类ProfileProvider:

public class UserProfileProvider : ProfileProvider
{
    #region Variables
    public override string ApplicationName { get; set; }
    public string ConnectionString { get; set; }
    public string UpdateProcedure { get; set; }
    public string GetProcedure { get; set; }
    #endregion

    #region Methods
    public UserProfileProvider()
    {  }

    internal static string GetConnectionString(string specifiedConnectionString)
    {
        if (String.IsNullOrEmpty(specifiedConnectionString))
            return null;

        // Check <connectionStrings> config section for this connection string
        ConnectionStringSettings connObj = ConfigurationManager.ConnectionStrings[specifiedConnectionString];
        if (connObj != null) …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc profile-provider

6
推荐指数
1
解决办法
1万
查看次数