您的位置:首页 > 其它

Profile 在 VS 2008 下之怪异问题求指点

2010-09-26 19:23 344 查看

2010-03-02 13:12 by ╭☆涩 轨ら, 135 visits,
网摘,
收藏,
编辑

今天本想使用 Profile 来完成几个 Demo 的,结果碰到一个稀奇的东西,

以前也没有注意到过,今天来用,突然问题就来了,

也不知道各位碰到过没有,碰到过的同行拜托指点一下啊,

问题是这样的:

首先,我在 web.config 中定义好了 Profile 节,在 VS 2005 中,

这些定义好的 Profile 下的 Properties 是可以直接在 VS 的智能提示下使用的,

并且会动态生成 Profile 和 ProfileCommon 两个类的,

而且在智能提示下也是可以直接使用这两个动态生成的类的,

而且这些智能提示是 Code-Behind 和直接把服务器代码写在页面中这两种模式都支持的,

但是今天在 VS 2008 下突然发现用不了,

而更让我惊奇的是在 VS 2008 中还只有使用 Code-Behind 时使用不了,

如果直接把服务器代码写在 .aspx 页面文件中的话,

却是可以使用 Profile 和 ProfileCommon ,

对此我是感到非常的奇怪啊!!!

再陈述一下吧,

首先我的 web.config 中配置如下





然后就是写一个 Demo ,先看一下使用 Code-Behind 的情况吧





上面的截图可以清楚的看到根本无法直接使用动态生成的 Profile 类,

然后我再使用将服务器端代码嵌入页面的方式来实现

<%@ Page Language="C#" AutoEventWireup="true"%>

<script runat="server">

protected void Page_Load(object sender, EventArgs e)

{

if (!User.Identity.IsAuthenticated)

{

FormsAuthentication.RedirectToLoginPage();

}

}

protected void btnSavaProfile_Click(object sender, EventArgs e)

{

if (User == null)

{

lblMsg.Text = "您为不合法用户!!!";

return;

}

if (!String.IsNullOrEmpty(txtAddress.Text))

{

Profile.住址 = txtAddress.Text;

}

if (!String.IsNullOrEmpty(txtPhone.Text))

{

if (rBtnListPhone.SelectedItem.Text == "家庭电话")

{

Profile.电话.家庭电话 = txtPhone.Text;

}

else

{

Profile.电话.移动电话 = txtPhone.Text;

}

}

if (!String.IsNullOrEmpty(txtConstellate.Text))

{

Profile.星座 = txtConstellate.Text;

}

Profile.Save();

lblMsg.Text == "添加成功";

}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

<style type="text/css">

.style1

{

width: 31%;

height: 205px;

}

.style2

{

height: 36px;

font-size: small;

}

.style3

{

height: 46px;

text-align: center;

}

.style4

{

height: 23px;

}

</style>

</head>

<body>

<form id="form1" runat="server">

<div style="font-family: 微软雅黑; font-size: small">

<table class="style1" style="border-color: #8000FF">

<tr>

<td>

住址

</td>

<td>

<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>

</td>

</tr>

<tr>

<td>

<asp:RadioButtonList ID="rBtnListPhone"

runat="server" Height="49px" Width="112px">

<asp:ListItem Selected="True">家庭电话</asp:ListItem>

<asp:ListItem>移动电话</asp:ListItem>

</asp:RadioButtonList>

</td>

<td>

<asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>

</td>

</tr>

<tr>

<td class="style2">

星座

</td>

<td class="style2">

<asp:TextBox ID="txtConstellate" runat="server"></asp:TextBox>

</td>

</tr>

<tr>

<td class="style3" colspan="2">

<asp:Label ID="lblMsg" runat="server" Style="color: #FF0066">

</asp:Label>

</td>

</tr>

<tr>

<td class="style4" style="text-align: right">

<asp:Button ID="btnSavaProfile" runat="server"

OnClick="btnSavaProfile_Click" Text="保存 Profile" />

</td>

</tr>

</table>

<br />

<br />

</div>

</form>

</body>

</html>

再来测试一下这个页面吧

我先以 XiaoZhen 进行登陆,然后再跳转到这个页面上来,





再给 XiaoZhen 添加 Profile





保存后再来看数据库





从这里可以知道直接将服务器代码嵌入在页面上这种方式来操作 Profile 是完全成功的,

但是前面那种使用 Code-Behind 为什么会不行呢?

什么命名空间没有导入这种问题我已经确定过了,不是这种问题,

也应该不是 VS 2008 不支持之类的(那 VS 2008 也做得太………)

是否还有 VS 2008 哪里需要设置后才能使用我就不得而知了,

所以想请个高人给指定一下,

还有就是为什么在 VS 2005 中是可以使用的?

2010—2—09
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: