在asp.net中为用户生成不同的ID [英] generate diffrent ids for users in asp.net

查看:55
本文介绍了在asp.net中为用户生成不同的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
当用户打开页面时,我有为每个用户生成的数字
第一个是IMP-20120505-1(imp(任何字)+现在-一天+1(最后一条记录或当表是临时性或天数是第一个条目时))
我希望当用户打开页面时,此页面上的用户ID会有所不同
喜欢
IMP-20120505-1
IMP-20120505-2
IMP-20120505-3
IMP-20120505-4
第二天
IMP-20120506-1
IMP-20120506-2
像这样

hi friend,
i have number that is generate for every users when user open the page
1st one is IMP-20120505-1(imp(any word)+now-a day+ 1(last record or when table is empity or days first entry))
i want to that id is generate different for users on this page when user open the page
like
IMP-20120505-1
IMP-20120505-2
IMP-20120505-3
IMP-20120505-4
next day
IMP-20120506-1
IMP-20120506-2
like this
if u have any idea about that plz ans me..

推荐答案

在您的项目中创建任何类.
将此静态成员放在此类中

create any class in your project.
put this static member in this class

public class AnyClass
    {
        public static int ind = 0;
        public static string lastDay = "";
    }



为您的asp.net项目添加一个global.asax文件

并配置您的application_start和session_start区域



add your asp.net project a global.asax file

and configure your application_start and session_start area

protected void Application_Start(object sender, EventArgs e)
       {
           AnyClass.lastDay = DateTime.Now.ToShortDateString();
       }

       protected void Session_Start(object sender, EventArgs e)
       {
           string toDay = DateTime.Now.ToShortDateString();

           // this will work only one times in a day. hour check the time after a new day. AnyClass.lastDay != toDay check if your computer time is am and pm. i didnt test clearly but i hope this will help you.
           if (DateTime.Now.Hour == 0 && (AnyClass.lastDay != toDay) && AnyClass.ind != 0)
           {
               AnyClass.ind = 0;
               AnyClass.lastDay = toDay;
           }
           AnyClass.ind++;
       }


不要忘记这将参加会议.您可以在web.config文件或iis下管理会话时间.

在您的项目中的任何地方调用您的AnyClass.ind


dont forget this will took in session. you can manage your sessions time in web.config file or under iis.

call your AnyClass.ind in your project anywhere


这篇关于在asp.net中为用户生成不同的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆