在ASP.NET成员强类型的配置文件值(MVC) [英] strong-typed profile values in ASP.NET membership (MVC)

查看:234
本文介绍了在ASP.NET成员强类型的配置文件值(MVC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了ASP.NET MVC基于会员登录了好几年,一切工作正常(它现在MVC3,但由于第一个版本这是MVC1成员没有变化)。现在我需要添加一个值到配置文件(只有一个价值,很少使用 - 所以它不保证定义成员资格提供或自定义表)

I've been using ASP.NET MVC with membership-based login for several years and everything is working fine (it's now MVC3, but membership didn't change since the first version which was MVC1). Now I need to add a value into the profile (just one value, of very seldom use - so it doesn't warrant custom membership provider or custom tables)

我得到了它通过 profile.SetPropertyValue(myprop)的工作,但我真的想获得 profile.myprop 工作。这可能吗?

I got it working through profile.SetPropertyValue("myprop"), but I would really want to get profile.myprop to work. Is it possible?

我看到了一些建议有一个自定义类我的配置文件:ProfileBase 并myprop作为类的属性。出于某种原因,铸造 ProfileBase.Create(currentUser.UserName)来我的资料给我一个错误(非法投)。

I saw some advise to have a custom class MyProfile : ProfileBase and have myprop as a property of that class. For some reason, casting ProfileBase.Create(currentUser.UserName) to MyProfile gives me an error (illegal cast).

有一个例子某处ASP MVC应用程序与档案,类似这样的老发表ScottGu 的?

Is there an example somewhere of ASP MVC application with Profile, similar to this Old Post by ScottGu?

推荐答案

乔尔斯波斯基有一个伟大的回答这个问题的对这个职位。你基本上是在正确的轨道上。

Joel Spolsky had a great answer to this question on this post. You're basically on the right track.

如果您收到非法投误差,其最有可能是由于在配置文件中的一个问题。确保这是包括在内;更具体的<型材defaultProvider =sqlProvider的继承=YourNamespace.AccountProfile方式> 部分

If you're getting the illegal cast error, its most likely due to a problem in the config file. Make sure this is included; more specifically the <profile defaultProvider="SqlProvider" inherits="YourNamespace.AccountProfile"> section.


     
     

<profile defaultProvider="SqlProvider" inherits="YourNamespace.AccountProfile">
    <providers>
         <clear />
         <add name="SqlProvider"
              type="System.Web.Profile.SqlProfileProvider"
              connectionStringName="sqlServerMembership" />
    </providers>
</profile>

这篇关于在ASP.NET成员强类型的配置文件值(MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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