我有一个asp项目,我试图发展用户配置文件的一部分,使用户可以用自己的个人资料(包含管理配置文件和用户)登录。
I have an asp project and I am trying to develop the user profile part, so that users can log in with their own profile (profile containing admin and users).
什么情况下可以设置用户计算机上的cookie,当用户登录,然后让网站用户浏览?我的意思后,经过我检查用户名和密码,通过在每个页面上查看该cookie我让用户浏览网页或重定向到登录页面。
Is it okay to set a cookie on users computer, when the user is logged in and then let the user browse in site? I mean after after I check user name and password, by checking this cookie on every page I let the user browse the page or redirect to the login page.
是这样好吗?这是安全使用?有没有更好的办法了吗?
Is this way okay? Is this safe to use? Is there any better approach for this?
推荐答案您可以使用的SqlProfileProvider。添加配置文件属性可以通过添加一些code到您的web.confing完成(部分System.Web程序里面,数据库sqlprofile结构必须是present):
You can use SqlProfileProvider. Adding profile properties can be done by adding some code to your web.confing (inside system.web section, database for sqlprofile structure must be present):
<profile defaultProvider="SqlProvider"> <providers> <clear/> <add name="SqlProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ASPNETDB" applicationName="MyApplication" description="SqlProfileProvider"/> </providers> <properties> <add name="LanguageId" allowAnonymous="false" type="System.Int32"/> <add name="Company" allowAnonymous="false" type="System.String"/> </properties> </profile>在这个例子中我已经添加了两个配置文件属性languageId NAD公司。您可以通过以下code访问此属性:
In this example I have added two profile properties languageId nad Company. You can access this properties using following code:
ProfileBase profile = ProfileBase.Create("SomeUserName"); string company = (string)profile["Company"];有关的SqlProfileProvider访问以下链接附加信息:
For additional info about SqlProfileProvider visit following link:
的msdn.microsoft/en-us/library/system.web.profile.sqlprofileprovider.aspx
更多推荐
在asp.net中用户配置文件
发布评论