Profile Property

G

Guest

Hi All,
I try to define profile in web.config as below
<anonymousIdentification enabled="true"/>
<profile enabled="true">
<properties>
<add name="logon" type="string" allowAnonymous="true" />
<add name="rule" type="string" allowAnonymous="true"/>
</properties>
</profile>

This is for store some temporary profile only. Then in web page I would like
to store some value in profile but I have problem to use it by call
Profile.logon ->error logon is not member of Profile or Profile("logon")
->error system.web.profile is a namespace and cannot be use as an expression.
Any idea? Thanks for any advise.

Madison
 
S

Steven Cheng[MSFT]

Hi Madison,

From your description, you're encoutering some problem when try using the
profile properties (with anonymous identity) in ASP.NET 2.0 application,
correct?

According to the error message below:

==============
error system.web.profile is a namespace and cannot be use as an expression.
================

I think it is more likely a code compilation problem rather than profile
property accessing problem. Would you post the code you use to access the
profile properties and where did you use the code? Here is a simple test
page that access and store profile properties(the same setting as you) I
used in my local test environment:

=============
public partial class test_ProfileTestPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<br/>logon: " + Profile.logon);
Response.Write("<br/>rule: " + Profile.rule);
}
protected void btnSet_Click(object sender, EventArgs e)
{
Profile.logon = txtLogon.Text;
Profile.rule = txtRule.Text;
}
}
===================

Please feel free to let me know if there is anything I missed here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi Steven,
Yes, I'm having problem using profile properies with anonymous for ASP.NET 2
Here is my coding:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Response.Write("Hi, " & Profile.logon)
Response.Write("Rule: " & Profile.rule)

End Sub
Private Sub gvMeasure_RowEditing(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvMeasure.RowEditing
Profile.logon = "Madison"
Profile.rule = "admin"
End Sub

The error message:
'logon' is not a member of Profile
'rule' is not a member of Profile

I got the errors from both sub routines. Do I have to imports some system?
It does not matter where I put the coding. It seems like no properties for
the profile. Should the properties show when I start to type Profile.?

Thank you for your advise.
 
S

Steven Cheng[MSFT]

Hi Madison,

I've also tested the code with a VB page, seems the code syntax and
configuration is correct. I think there might be something else cause the
problem. What's the ASP.NET project type, are you using the default
"WebSite" project or "Web Application Project"(VS 2003/ASP.NET 1.1 style)?
I've found some web threads discussing on the similar issue when using "Web
Applicaton Project".

Also, I can send you a simple test project(website) that contains test page
to use the profile properties so that you may test it on your side. You can
shot me a message through the email in my signature(remove the "online") so
that I can get your address.

Please feel free to let me know if there is anything else need help.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi Steven,
Yes, I use Web Application Project for my web application. Could you point
me to the website with discussing? I would appreciate if you could give me
the sample project how to work around?

Thanks.
Madison
 
S

Steven Cheng[MSFT]

Hi Madison,

Thanks for your followup and I have received your offline email. Sorry for
the late reponse as I got a cold last weekend and took leave these days.

I originally test through a web site project, I'll also perform some test
against web application project, and will send you a simplified one if I
still get it working.

Meanwhile, you can also try it in a web site appliation to see whether it
works.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Madison,

I've performed some further research and did found this profile problem
with "Web applicaton project". Actually, this "Profile" property does
haven't been generated in "Web Application Project"'s page. Here is a MSDN
forum FAQ article mentioned some known issue of web application project and
the profile property issue is one of them

££FAQ and Known Issues Web Application Projects
http://forums.asp.net/t/988775.aspx

A workaround available now is using a utility to manually generator such a
profile accessor(mentioned in the FAQ article). Or if do not want to
manually generate the accessor class, you can use the "ProfileBase" class
to access the profile properties, however, you can only use property name
to access the profile properties through a hashtable style approach rather
than strong-typed class member(like in web site application). Here is the
code snippet demonstrate on this:

====================
Protected Sub btnSet_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSet.Click

Dim p As ProfileBase
p = Context.Profile

Response.Write("<br/>" + p.GetPropertyValue("rule").ToString())

p.SetPropertyValue("rule", "new value")

End Sub
=========================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Madison,

Any further question on this issue or does the info in my last reply helps
some? If there is anything else we can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Thank you for your follow up.

I just try to figure how to keep Session() longer than 20 mins without
changing the setup. We try to write web application for people out side of
our organize to entry data and save backup to our database. These users can
stay in the application for a day or shorter. We have any level of user
(admin, data-enter, audit). We thought Profile will be good idea but we do
not want to save any profile in the database or using any cookies. If I can
use Profile with anonymous user will be good idea.

Any recommends welcome.

Madison.
 
S

Steven Cheng[MSFT]

Thanks for your reply Madison,

As for the "keep session longer than 20 mins without changing setup", do
you mean the ASP.NET sessionstate timeout?

And for the profile, you can surely use them (no matter in Web application
project or default web site project). And in web application project, you
need to use the HttpContext.Profile property to access the current user's
Profile( authenticated user or anonymous user). And to access profile
properties, you need to use "GetPropertyValue" and "SetPropertyValue"
methods:

=====================
Protected Sub btnSet_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSet.Click

Dim p As ProfileBase
p = Context.Profile

Response.Write("<br/>" + p.GetPropertyValue("rule").ToString())

p.SetPropertyValue("rule", "new value")

End Sub
========================

In addition, you can use "Context.Profile.Username" to printout the
profile's username(if under anonymous status, it will refer to the
anonymous user's generatd identity. Does this helps you for your current
issue?

Please let me know if you have any furher concerns or need any helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi Steven,

I have some question about Anonymous Profiles. Do anonymous profiles need to
store data to database? When I tried to use the sample code I can not get
thru the page, it give me the message say that
'An error has occurred while establishing a connection to the server. When
connecting to SQL Server 2005, this failure may be caused by the fact that
under the default settins SQL Server does not allow remote connections.
(provideer: SQL Network Interfaces, error: 26 - Error Locating
Server/Instance Specified)'

I knew I can connection to my SQL Server 2005 because I'm be able to
retrieve information, add or edit/save back to table. I thought annonymous
profiles stores information in the cookies.

Thank you.
Madison
 
S

Steven Cheng[MSFT]

Hi Madison,

Whether the profile properties will be stored in database or not depend on
the profile provider you use. By default ASP.NET 2.0 Profie service(also
other services such as membership) use the SQL Server provider(connect to
local SQLExpress instance). So each user(anonymouse or named one)'s
properties will be stored in database. Yes, anonymous identification does
rely on cookie, but that doesn't means it will store all the properties in
cookie, it only store an identity(just like the username for named user)
since it will need it (retrieve back later you visit the page as anonymous
user again) to mapp the stored data in database. Does this affect your
current application or code logic?

Please feel free to let me know if there is anything need help.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Madison,

Any progress on this or still any questions need help? If so, please don't
hesitate to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi Steven,

Thank you very much for your help.

I think I got the hand on it. The problems happened because I do not install
SQL Express provider in my machine and most the sample keep talking about SQL
Express. When I run aspnet_regsql.exe to create the profile database then the
problems solved. Thank you again for you help.

Madison.
 
S

Steven Cheng[MSFT]

You're welcome Madison,

I'm glad that you've got it working now.

Have a nice day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top