在ASP.NET应用程序中使用配置文件

编程入门 行业动态 更新时间:2024-10-10 16:15:19
本文介绍了在ASP.NET应用程序中使用配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复:结果  如何分配配置文件值?

我在读一本书ASP.NET,说如果你选择的Web应用程序,当你启动一个项目,你不能使用个人资料。它只网站下运行。

I'm reading an ASP.NET book that says you can't use Profile if you select Web Application when you start a project. It only run under Web Site.

是否有Web应用程序的任何替代方案?或者,你需要建立自己的档案系统。

Are there any alternatives for Web Application? Or do you need to build your own Profile system.

推荐答案

您,如果您使用的是Web应用程序,而不是一个网站,可以使用配置文件提供,但开箱从一个aspx页面code背后你将不能够做到 Profile.MyProperty 。

You can use the profile provider if you are using a web application instead of a web site, but out of the box from an aspx page code behind you will not be able to do Profile.MyProperty.

这是不是一个大问题与努力一点点,你就可以做同样的事情。这个例子中提供网站项目转换为Web应用程序项目是如何使用配置文件提供一个Web应用程序一个很好的起跳点。

This isn't a big deal as with a little bit of effort you will be able to do something similar. The example providing in Converting a Web Site Project to a Web Application Project is a good jumping off point on how to use the profile provider with a web application.

要总结上述条文的转换配置文件对象code段创建一个的ProfileCommon 类

To summarize the Converting Profile Object Code section of the aforementioned article create a ProfileCommon class

public class ProfileCommon { public Teachers Teachers { get { return (Teachers) HttpContext.Current.Profile.GetPropertyValue("Teachers"); } set { HttpContext.Current.Profile.SetPropertyValue("Teachers",value); } } }

然后在你的aspx code后面你现在可以做的。

Then on your aspx code behind you can now do

ProfileCommon Profile = new ProfileCommon(); protected void Button1_Click(object sender, EventArgs e) { Teachers teachers = new Teachers(); teachers.Add(new Teacher("scott")); teachers.Add(new Teacher("bob")); teachers.Add(new Teacher("paul")); Profile.Teachers = teachers; }

要实例化一个替代的的ProfileCommon 为每个页面字段将使它和它的方法静态的,只需要调用从code屁股类的属性 Profile.Teachers

An alternative to instantiating the ProfileCommon as a field for each page would be to make it and its methods static and just call the class properties from the code behinds Profile.Teachers

public static class Profile { public static Teachers Teachers { //...... } }

这是不是一个巨大的优势,但是让你的code更类似于一个ASP.NET网站项目。

This isn't a huge advantage, but makes your code more similar to that of a ASP.NET Web Site project.

的社评不相关答案的有两个项目类型之间的主要区别,但我的项目,我preFER Web应用程序。我有偏见,因为开创了TFS构建经理的生成配置文件是Web应用程序项目更容易比它是为网站项目。而且它似乎像微软强调网站的项目,然后从他们赞成Web应用程序项目的支持了。

Editorial Commentary not pertinent to the answer There are key differences between the two project types, but for my projects I prefer web applications. I have a bias because creating a build profile for the TFS Build Manager is much easier for Web Application projects than it is for Web Site projects. Further it seems like Microsoft emphasized Web Site projects and then backed away from them in favor of Web Application projects.

更多推荐

在ASP.NET应用程序中使用配置文件

本文发布于:2023-11-12 14:02:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581706.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:配置文件   应用程序   ASP   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!