1 关于ascx如何从所在的页面中取页面传递的值?
在ascx.cs中Page_Load()中,可直接调用Request[<Key>]来取
--------------------------------------
2 在ascx中如何改变所在页面aspx中控件的值?
System.Web.UI.WebControls.TextBox ctl;
//System.Web.UI.HtmlControls.***
//有两个控件集,Web和 Html
ctl = (System.Web.UI.WebControls.TextBox)Page.FindControl("TextBox1");
//取到后,进行相应的操作
--------------------------------------
3 转字符型的函数:
1 Convert 2 int.Parse
--------------------------------------
4 在ascx中使用HttpContext用:
HttpContext.Current.Response,
HttpContext.Current.Cache
Response.Redirect 改变页面的目录
HttpContext.Current.Request.QueryString
--------------------------------------
5 获取浏览期的类型可用:
if ( HttpContext.Current.Request.UserAgent.IndexOf( "Windows NT 5.2" ) >= 0 )
platform = "Win2003";
HttpContext.Current.Session.SessionID,
PageBoardID,
User.Name,
HttpContext.Current.Request.UserHostAddress,
//ip HttpContext.Current.Request.FilePath,
HttpContext.Current.Request.Browser.Browser,
//浏览器 HttpContext.Current.Request.Browser.Platform,
//系统
--------------------------------------
6 关于 Hashtable
//create
System.Collections.Hashtable t = Mession.ForumRead;
if ( t == null )
{
t = new System.Collections.Hashtable();
}
t [forumID] = date;
//取
System.Collections.Hashtable t = Mession.ForumRead;
if ( t == null || !t.ContainsKey( forumID ) )
return ( DateTime ) Mession.LastVisit;
else
return ( DateTime ) t [forumID];
--------------------------------------
7 关于字符川格式的组成:
ctl.Text= string.Format( "{0};{1};{2}", "wo", "12", "iop" );
//结果是:wo;12;iop
--------------------------------------
8.yaf论坛的页面引导方式:
******
Pages page; //引导的集合
string m_baseDir = Data.ForumRoot;
try
{
page = ( Pages ) System.Enum.Parse( typeof( Pages ), Request.QueryString ["g"], true );
//g的值:forum,topics,posts...等. 从首页上的工具栏调用
}
catch ( Exception )
{
page = Pages.forum;
}
if ( !ValidPage( page ) )
{
Forum.Redirect( Pages.topics, "f={0}", LockedForum );
}
//根据集合中的字符串,生成需要加载的页面
string src = string.Format( "{0}pages/{1}.ascx", m_baseDir, page );
if ( src.IndexOf( "/moderate_" ) >= 0 )
src = src.Replace( "/moderate_", "/moderate/" );
if ( src.IndexOf( "/admin_" ) >= 0 )
src = src.Replace( "/admin_", "/admin/" );
if ( src.IndexOf( "/help_" ) >= 0 )
src = src.Replace( "/help_", "/help/" );
try
{
pages.ForumPage ctl = ( pages.ForumPage ) LoadControl( src );
ctl.ForumControl = this;
this.Controls.Add( ctl );
//
}
catch ( System.IO.FileNotFoundException )
{
throw new ApplicationException( "Failed to load " + src + "." );
}
****************
public System.Web.UI.Control LoadControl(string virtualPath)
System.Web.UI.TemplateControl 的成员
摘要:
根据指定的虚拟路径从文件加载 System.Web.UI.Control 对象。
参数:
virtualPath: 控件文件的虚拟路径。
返回值:
返回指定的 System.Web.UI.Control。
******ForumControl**定义如下
private Forum m_forumControl = null;
public yaf.Forum ForumControl
{
get
{
if ( m_forumControl != null )
return m_forumControl;
System.Web.UI.Control ctl = Parent;
while ( ctl.GetType() != typeof( yaf.Forum ) )
ctl = ctl.Parent;
m_forumControl = ( yaf.Forum ) ctl;
return m_forumControl;
}
set
{
m_forumControl = value;
}
}
********
public class Forum : System.Web.UI.UserControl
******************
public enum Pages
{
forum,
topics,
posts,
profile,
activeusers,
moderate,
postmessage,
mod_forumuser,
attachments,
pmessage,
movetopic,
emailtopic,
printtopic,
members,
cp_inbox,
cp_profile,
cp_editprofile,
cp_editavatar,
cp_signature,
cp_subscriptions,
cp_message,
login,
approve,
info,
rules,
register,
search,
active,
logout,
moderate_index,
moderate_forum,
error,
avatar,
admin_admin,
admin_hostsettings,
admin_boards,
admin_boardsettings,
admin_forums,
admin_bannedip,
admin_smilies,
admin_accessmasks,
admin_groups,
admin_users,
admin_ranks,
admin_mail,
admin_prune,
admin_pm,
admin_attachments,
admin_eventlog,
admin_nntpservers,
admin_nntpforums,
admin_nntpretrieve,
admin_version,
admin_bannedip_edit,
admin_editaccessmask,
admin_editboard,
admin_editcategory,
admin_editforum,
admin_editgroup,
admin_editnntpforum,
admin_editnntpserver,
admin_editrank,
admin_edituser,
// Added BAI 07.01.2004
admin_reguser,
// Added BAI 07.01.2004
admin_smilies_edit,
admin_smilies_import,
// Added Rico83
admin_replacewords,
admin_replacewords_edit,
im_yim,
im_aim,
im_icq,
im_email,
rsstopic,
help_index,
help_recover,
lastposts
}
--------------------------------------
9.所有的ascx 都从类ForumPage中继承。调用基类的函数用 :base
public partial class login : ForumPage
{
public login()
: base( "LOGIN" )
{
}
--------------------------------------
10.比如调用注册时,中间有参数:ReturnUrl.为返回的地址.
这种设计思路:
Default.aspx?g= 只有一个参数
Default.aspx页面中控件"<yaf:forum runat="server" id="forum" />"接受到参数后,根据参数的类别改边自身对应的ascx文件.
控件"<yaf:forum runat="server" id="forum" />"中引发调用其他的页面的时间.用Pages.info来获取 Default.aspx的内容,再加上相应的参数. 控件中的刷新,引起页面(Default.aspx)中的刷新.
--------------------------------------
11.c#中把n行字符放在一个变量中,使用 @.如下:
string javascript = string.Format( @"
<script language=""javascript"">
var called = false;
}");
--------------------------------------
12.登陆成功后,调用:
string idName = string.Format( "{0};{1};{2}", userID, PageBoardID, UserName.Text );
if ( Request.QueryString ["ReturnUrl"] != null )
{
FormsAuthentication.RedirectFromLoginPage( idName, AutoLogin.Checked );
}
else
{
FormsAuthentication.SetAuthCookie( idName, AutoLogin.Checked );
Forum.Redirect( Pages.forum );
}
*********************
public sealed class FormsAuthentication
System.Web.Security 的成员
摘要:
为 Web 应用程序管理 Forms 身份验证服务。无法继承此类。
*******
public static void SetAuthCookie(string userName, bool createPersistentCookie, string strCookiePath)
System.Web.Security.FormsAuthentication 的成员
摘要:
为提供的用户名创建一个身份验证票证,并使用提供的 Cookie 路径或 URL 将其添加到响应的 Cookie 集合。
参数:
userName: 已验证的用户的名称。
createPersistentCookie: 若要创建持久 Cookie(跨浏览器会话保存的 Cookie),则为 true;否则为 false。
strCookiePath: Forms 身份验证票证的 Cookie 路径。
********
public static void RedirectFromLoginPage(string userName, bool createPersistentCookie)
System.Web.Security.FormsAuthentication 的成员
摘要:
将经过身份验证的用户重定向回最初请求的 URL 或默认 URL。
参数:
userName: 经过身份验证的用户名。
createPersistentCookie: 若要创建持久 Cookie(跨浏览器会话保存的 Cookie),则为 true;否则为 false。
**************
public string RawUrl { get; }
System.Net.HttpListenerRequest 的成员
摘要:
获取客户端请求的 URL 信息(不包括主机和端口)。
返回值:
System.String 包含此请求的原始 URL。
--------------------------------------
13 .如果要集成的话,调用
string idName = string.Format( "{0};{1};{2}", userID, PageBoardID, UserName.Text ); 1
FormsAuthentication.SetAuthCookie( idName, false );