第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在ASP.NET MVC中實現(xiàn)配置文件提供程序

在ASP.NET MVC中實現(xiàn)配置文件提供程序

拉丁的傳說 2019-10-15 15:47:13
為了我的一生,我無法讓SqlProfileProvider在我正在處理的MVC項目中工作。我意識到的第一個有趣的事情是Visual Studio不會自動為您生成ProfileCommon代理類。沒什么大不了的,因為擴展ProfileBase類很簡單。創(chuàng)建ProfileCommon類之后,我編寫了以下Action方法來創(chuàng)建用戶個人資料。[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"); }我遇到的問題是對ProfileCommon.Create()的調(diào)用無法轉(zhuǎn)換為ProfileCommon類型,因此我無法取回我的配置文件對象,這顯然會導(dǎo)致下一行失敗,因為profile為null。以下是我的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" />        <add name="Company" type="string" />        <add name="Phone" type="string" />        <add name="Fax" type="string" />        <add name="City" type="string" />        <add name="State" type="string" />        <add name="Zip" type="string" />        <add name="Email" type="string" >    </properties></profile>MembershipProvider工作順利,所以我知道連接字符串很好
查看完整描述

3 回答

?
海綿寶寶撒

TA貢獻1809條經(jīng)驗 獲得超8個贊

嘗試使用Web Profile Builder。它是一個構(gòu)建腳本,可以從web.config自動生成一個WebProfile類(等效于ProfileCommon)。


查看完整回答
反對 回復(fù) 2019-10-15
?
侃侃爾雅

TA貢獻1801條經(jīng)驗 獲得超16個贊

不確定整個問題,但是我在您的代碼中注意到了一件事:


ProfileCommon profile = (ProfileCommon)ProfileCommon.Create(user.UserName, user.IsApproved) as ProfileCommon;

您不需要(ProfileCommon)和as ProfileCommon。它們都執(zhí)行強制類型轉(zhuǎn)換,但是()引發(fā)異常,而as如果無法進行強制類型轉(zhuǎn)換,則返回null。


查看完整回答
反對 回復(fù) 2019-10-15
  • 3 回答
  • 0 關(guān)注
  • 538 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號