crm的具体问题:如何实现
墨初 知识笔记 111阅读
One of the internationalization? Create project resource language 2. Add resource file resource language. resx, and add data (it is best not to add data with hypertext markup language tags, which will cause compilation errors). At this point, the path of the resource file should be resource language. resource language. resource. For the convenience of calling, we can generally set the namespace of the project to be empty, so that when calling, we only need to access it through the resource language and resources. 3. The following is the loading resource file: conststringbaseresource=' resourcelanguageassemblyprimaryresource=assembly.load (baseresourcefile); Application ['RM']=new resource manager (basic resource); 4. Add an attribute to obtain the resource package public classroot.d=' code highlighter 1 _ 20 _ 248 _ closed _ text' style=' border : 1px solid rgba (128,128,128,1); Display : None; background-color: rgba(255,255,255,1)' { public root(){ } privatesticresourcemanager _ RM; publistaticresourcemanagerrm { get { if
olor: rgba(0, 0, 0, 1)">(_rm==null)_rm = (ResourceManager) HttpContext.Current.Application["RM"];
return _rm;
}
}
} 5.调用
(注意:国际化文档时,value值如果用到了HTML标记,请注意标记一定要规范,部分标记无法使用,不然会报告错误,如使用 标记,会报告xmlvalidatingreader 并相应地设置 entityheadling 属性的错误)
1.web.config设置,采用Forms身份验证方式:
<forms name=".CRM" protection="All" timeout="60" loginUrl="login.aspx" slidingExpiration="true" />
</authentication>
<system.web>
<authorization>
<allow roles="SystemAdministrator,MembershipAdministrator" />
<deny users="*" />
</authorization>
</system.web>
<location path="ShowAllUsers.aspx">
<system.web>
<authorization>
<allow roles="SystemAdministrator,MembershipAdministrator" users="?" />
</authorization>
</system.web>
</location>
</configuration>
int version, //设为1
string name, //用户标示
DateTime issueDate, //Cookie 的发出时间, 设置为 DateTime.Now
DateTime expiration, //过期时间
bool isPersistent, //是否持久性(根据需要设置,若是设置为持久性,在发出
cookie时,cookie的Expires设置一定要设置)
string userData, //这里用上面准备好的用逗号分割的role字符串
string cookiePath // 设为"/",这要同发出cookie的路径一致,因为刷新cookie
要用这个路径
);
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket (1,"kent",DateTime.Now, DateTime.Now.AddMinutes(30), false,UserRoles,"/") ;
4.生成验证票
string HashTicket = FormsAuthentication.Encrypt (Ticket) ;
//生成cookie
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket) ;
通过Response.Cookies.Add(UserCookie) 将身份验证票Cookie附加到输出的cookie集合中,发送到客户端.
6.重定向到用户申请的初试页面.
Context.Response.Redirect (Context.Request["ReturnUrl"]) ;
7.基于角色访问授权
{
HttpApplication App = (HttpApplication) sender;
HttpContext Ctx = App.Context ; //获取本次Http请求相关的HttpContext对象
if (Ctx.Request.IsAuthenticated == true) //验证过的用户才进行role的处理
{
FormsIdentity Id = (FormsIdentity)Ctx.User.Identity ;
FormsAuthenticationTicket Ticket = Id.Ticket ; //取得身份验证票
string[] Roles = Ticket.UserData.Split (',') ; //将身份验证票中的role数据转成字符串数组
Ctx.User = new GenericPrincipal (Id, Roles) ; //将原有的Identity加上角色信息新建一个GenericPrincipal表示当前用户,这样当前用户就拥有了role信息
}
}
1.重载LoadPageStateToPersistenceMedium方法
{
if (_formatter == null)
{
_formatter = new LosFormatter();
}
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE#"))
{
throw new Exception("Invalid viewstate key:" + str);
}
#if VIEWSTATETOSQLSERVER
//从数据库中获取ViewState,参数为SessionID
db.GetViewState(a);
//操作失败则跳转到上一页面
//返回序列化后的viewstate
return _formatter.Deserialize(viewState);
#else
if (!str.StartsWith("VIEWSTATE#"))
{
throw new Exception("Invalid viewstate key:" + str);
}
return Cache[str];
#endif
}
{
string str = "VIEWSTATE#" + Session.SessionID.ToString() + "#" + DateTime.Now.Ticks.ToString();
//自动注册隐藏字段
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
if (_formatter == null)
{
_formatter = new LosFormatter();
}
#if VIEWSTATETOSQLSERVER
StringWriter _writer = new StringWriter();
_formatter.Serialize(_writer, viewState);
//$$$$$$$$$此处插入将viewstate写入数据库,需要提供参数:Request.Path,用户ID,SessionID,ViewState$$$$$$$$$
//如果操作失败,则从数据库中删除sessionID对应的所以记录
db.InsertSession(a,b,c,d);
#else
Cache.Add(str, viewState, null, DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero, CacheItemPriority.Default, null);
#endif
}
