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 中配置如下
![](http://images.cnblogs.com/cnblogs_com/QinBaoBei/WindowsLiveWriter/ProfileVS2008_8828/image_thumb.png)
然后就是写一个 Demo ,先看一下使用 Code-Behind 的情况吧
![](http://images.cnblogs.com/cnblogs_com/QinBaoBei/WindowsLiveWriter/ProfileVS2008_8828/image_thumb_1.png)
上面的截图可以清楚的看到根本无法直接使用动态生成的 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 进行登陆,然后再跳转到这个页面上来,
![](http://images.cnblogs.com/cnblogs_com/QinBaoBei/WindowsLiveWriter/ProfileVS2008_8828/image_thumb_2.png)
再给 XiaoZhen 添加 Profile
![](http://images.cnblogs.com/cnblogs_com/QinBaoBei/WindowsLiveWriter/ProfileVS2008_8828/image_thumb_3.png)
保存后再来看数据库
![](http://images.cnblogs.com/cnblogs_com/QinBaoBei/WindowsLiveWriter/ProfileVS2008_8828/image_thumb_4.png)
从这里可以知道直接将服务器代码嵌入在页面上这种方式来操作 Profile 是完全成功的,
但是前面那种使用 Code-Behind 为什么会不行呢?
什么命名空间没有导入这种问题我已经确定过了,不是这种问题,
也应该不是 VS 2008 不支持之类的(那 VS 2008 也做得太………)
是否还有 VS 2008 哪里需要设置后才能使用我就不得而知了,
所以想请个高人给指定一下,
还有就是为什么在 VS 2005 中是可以使用的?
2010—2—09
相关文章推荐
- VS 2008 SP1及其问题
- vs 2008编程遇到的小问题
- 使用vs 2008创建项目,没出现解决方案的问题
- vs 2008链接到TFS 2010 出现问题
- 解决:VS 2005/2008 中 fstream 不能处理带有中文路径的问题
- sql 2008 和 vs 2010 连数据库问题
- 问大家一个简单的vs 2008调试的问题?
- vs 2008 过期问题
- vs 2008 asp设计视图不能用的问题解决(肯定可行!这个问题搞的我好晕!)
- VS 2008 SP1及其问题
- VS 2008 和.NET 3.5 Beta2常见问题的解决方案
- 安了个vs 2008 express后,诡异asp.net Ajax PageMethods的问题,怎么解决?
- VS2008环境下开发的某些程序在其他机器运行提示“由于应用程序配置不正确,应用程序未能启动”的问题(IIS)
- vs 2008 2005 2010同时安装,2010版本va破解失效的问题
- Vs 2008 sp1更新后出现的问题!
- VS 2008的问题
- VS 2005/2008生成程序的自动版本号问题
- 解决 VS 2008 不能创建新项目,“The tools version “3.5″ is unrecognized ” 问题
- VS 2008和.NET 3.5 Beta2常见问题的解决方案
- 关于vs 2008字符集问题