如何在asp.net中调用服务器页面中的配置文件 [英] how to call profile in server page only in asp.net

查看:71
本文介绍了如何在asp.net中调用服务器页面中的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

个人资料defaultprovider =MyProfileProvider>

个提供者>

< add> name =MyProfileProvidertype =System.Web.Profile.SqlProfileProviderconnectionStringName =dbconnection/>

/ add>

/ providers

/ profile>

profile defaultprovider="MyProfileProvider">
providers>
<add> name="MyProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="dbconnection" />
/add>
/providers
/profile>

推荐答案

您可以在MSDN上查找资源,他们拥有适合其产品的优质资源库。 个人资料元素在这里定义和描述,



http://msdn.microsoft.com/en-us/library/ms164644(v = vs.85)的.aspx [ ^ ]



您还可以在 http://msdn.microsoft.com/en-us/library/vstudio/d8b58y5d(v = vs.100).aspx [ ^ ]



示例代码是这样的,如果您的个人资料定义为



You can look for resources on MSDN, they have a great library of resources for their products. The profile Element is defined and described here,

http://msdn.microsoft.com/en-us/library/ms164644(v=vs.85).aspx[^]

You can also get a tutorial on this topic, at http://msdn.microsoft.com/en-us/library/vstudio/d8b58y5d(v=vs.100).aspx[^]

Sample code is like this, if you're having your profile defined as

<profile defaultProvider="AspNetSqlProfileProvider">
  <properties>
     <add name="Name" />
     <add name="Weight" type="System.Int32" />
     <add name="BirthDate" 

          type="System.DateTime" />
  </properties>
</profile>





您可以在ASP.NET代码中获得它的价值





You can get its value in your ASP.NET code as

// if the programming language is C#, then
DateTime bday = Profile.BirthDate;





你必须始终至少一次谷歌你的问题,有一个解决方案准备好你与...合作。祝你好运!



You must always at least once Google your problems, there is a solution ready for you to work with. Good luck!


Web应用程序项目(WAP)和网站之间的配置文件差异

2008年4月12日星期六ASP.NET WAP

配置文件服务是为用户添加自定义属性的一种非常有用且简单的方法,它不包含在标准MembershipUser属性中...



例如,您可能需要添加婚姻状况,出生日期,地址....所有这些都是您在开发项目时可能需要的自定义属性...



如果您熟悉Profile ..您将知道使用配置文件时必须做的第一件事是在web.config文件中设置配置文件属性,



例如,您可以为用户个人资料添加出生日期,地址,婚姻状况,如下所示,



< profile>

< properties>

< add name =DateOfBirthtype =DateTime>

< add name =Addresstype =String>

< add name =MaritalStatustype =String>







保存文件后,在网站项目下工作,



您会注意到,如果您在后面的页面代码中输入了个人资料,您将看到为您生成的属性,如下图所示:







这是因为Visual Studio创建了一个名为ProfileCommon的新类,Thats继承了ProfileBase,并为其添加了新的属性..



请注意,当你在web.config中更改配置文件属性时,visual studio将始终更新该类...



现在,如果您正在使用Web应用程序项目,您会注意到将配置文件属性添加到web.config将不会在页面后面的代码中向Profile对象添加任何属性....这是因为Visual Studio不生成profileCommon类...



您需要使用ProfielBase.GetPropert访问属性yValue(PropertyName)



例如,要访问DateOfBirth属性,您需要使用此代码



Dim DOB As DateTime = CDate(HttpContext.Current.Profile.GetPropertyValue(DateOfBirth))



在这篇文章中,我谈到了配置文件之间的差异普通网站和WAP项目,请注意它们之间还有很多其他差​​异,例如,当使用资源文件时,网站会提供强大的打字功能。


资源属性也由Visual Studio处理...



如果在asp.net使用网站使用配置文件的原因如此PLZ
The Differences in Profile between Web Application Projects (WAP) and website
Saturday, April 12, 2008 ASP.NET WAP
The profile services is a very helpful and easy way to add custom properties for your users which is not contained in the Standard MembershipUser Properties...

for example , you may need to add the Marital status , Date of Birth, Address.... all of these are custom properties that you may need them while developing your projects ...

If you are familiar with Profile .. you will know that the first thing that must done when working with profiles is to set the Profile properties in web.config File ,

for example ,you can add the Date of Birth, address, Marital status for the user profile as follows,

<profile>
<properties>
<add name="DateOfBirth" type="DateTime">
<add name="Address" type="String">
<add name="MaritalStatus" type="String">



after saving the file , and working under a website project ,

you will notice that if you typed profile in the page code behind , you will see the properties generated for you as in the picture below:



this happened because the Visual studio created a new class called ProfileCommon Thats inherits ProfileBase , and adds the new properties to it ..

Note that visual studio will always update that class when you change the Profile properties in web.config ...

Now , if you are working with web application projects , you will notice that adding the Profile properties to web.config will not add any properties to Profile object in the code behind of the page.... this is because Visual studio doesn't generate a profileCommon class ...

instead you need to access the properties using ProfielBase.GetPropertyValue(PropertyName)

for example , to access the DateOfBirth property , you need to use this code

Dim DOB As DateTime = CDate(HttpContext.Current.Profile.GetPropertyValue("DateOfBirth"))

In this post , I talked about the Differences in Profile between the normal website and WAP projects , Note that there is a lot of other differences between them, for example ,

when working with resource files , the website will provide a strong typing for resources properties which is also handled by Visual studio ...

that a reason so plz if used profile in asp.net using website


这篇关于如何在asp.net中调用服务器页面中的配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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