.net 网站开发知识点一

一、form验证

网站 开发后台文件放在一个文件夹里,在URL中输入没有验证的页面不允许访问,我们采取form验证,在webConfig文件夹里的文件如下:

<?xml version="1.0"?>
<configuration>
    <appSettings />
    <connectionStrings />
   <system.web>
      <compilation debug="true">
      </compilation> 
      <authentication mode="Forms">
        <forms loginUrl="Backstage/Login.aspx" defaultUrl="Backstage/Default.aspx" timeout="1"></forms>
      </authentication>   
    </system.web>
  <location path="Backstage">
    <system.web>
      <authorization>       
        <deny users="?"/>      
      </authorization>
    </system.web>
  </location>
</configuration>

○ defaultUrl:定义在身份验证之后用于重定向的默认 URL。默认值为default.aspx ;

○ loginUrl:指定如果找不到任何有效的身份验证 Cookie,将请求重定向到的用于登录的 URL。默认值为login.aspx .

timeout cookie过期时间,单位是分钟

<authorization> 授权:顺序是先写allow,再写deny,不然就会出现问题。

allow :向授权规则映射添加一个规则,该规则允许对资源进行访问。

deny :向授权规则映射添加一条拒绝对资源的访问的授权规则。

这样访问Backstage文件夹里的文件都会先访问login.aspx


在后台添加代码

  FormsAuthentication.RedirectFromLoginPage("陈琪", false);  

陈琪即用户名,User.Identity.Name可获取登录用户名

注销代码 FormsAuthentication.SignOut();


二、FCKediter控件的使用

本控件可以轻松更改界面,同时满足发布新闻的一些基本要求,加入图片和插入超链接,工具包可以在这下载工具包


文件夹放在根目录下,.dll则引用,工具箱内添加后将会有控件,在webConfig里配置后,直接引用即可,代码如下

<appSettings>
    <add key="FCKeditor:BasePath" value="~/fckeditor/"/>
    <add key="FCKeditor:UserFilesPath" value="~/upload/" />
  </appSettings>

BasePase:fckeditor所在目录,UserFilesPath:上传的图片所在目录,这里设置完,上传图片可能会报错

FCKeditor出现"this connector is disabled Please check the"editor/filemanager/connectors/aspx/config.aspx"

解决办法:

打开editor/filemanager/connectors/aspx/config.ascx修改CheckAuthentication()方法,返回true


fckeditor面板样式更改,在fckeditor文件夹里的,fckconfig.js文件里

FCKConfig.ToolbarSets["Basic"] =
[
	['Source', 'DocProps', '-', 'Save', 'NewPage', 'Preview', '-', 'Templates'],
	['Cut', 'Copy', 'Paste', 'PasteText', 'PasteWord', '-', 'Print', 'SpellCheck'],
	['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
	['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
	'/',
	['Bold', 'Italic', 'Underline', 'StrikeThrough', '-', 'Subscript', 'Superscript'],
	['OrderedList', 'UnorderedList', '-', 'Outdent', 'Indent', 'Blockquote'],
	['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull'],
	['Link', 'Unlink', 'Anchor'],
	['Image', 'Flash', 'Table', 'Rule', 'Smiley', 'SpecialChar', 'PageBreak'],
	'/',
	['Style', 'FontFormat', 'FontName', 'FontSize'],
	['TextColor', 'BGColor'],
	['FitWindow', 'ShowBlocks', '-', 'About']		// No comma for the last row.
];
FCKConfig.ToolbarSets["Default"] = [
    ['Copy', 'PasteText', 'PasteWord', 'Bold', 'Italic', 'TextColor', 'BGColor', '-', 'OrderedList', 'UnorderedList'], ['Link', 'Unlink', 'Anchor'],
	['Image', 'Flash', 'Table', 'Rule', 'Smiley', 'SpecialChar', 'PageBreak'], ['Style', 'FontFormat', 'FontName', 'FontSize']
];

FCKConfig.EnterMode = 'p' ;			// p | div | br
FCKConfig.ShiftEnterMode = 'br' ;	// p | div | br
["Basic"]里就是具备的所有功能,["Default"]里就是面板上显示的功能,你可以根据需要修改,FCKConfig.EnterModer是文字面板中回车的作用,有3种可选。

添加到数据库时:

 news.NewsText =FckEditor.Value.Trim();     

读取时后台读取,前台显示

 //新闻内容
 public string NewsText { get; set; }
 this.NewsText = Regex.Replace(news.NewsText, "<br />", "<p>");
前台直接调用即可:

<div style=" text-align:justify; width:550px; overflow:hidden "> <%=NewsText%> <br /><br /></td>

三、分页控件的使用

此空间引入AspNetPager.dll,将控件拖入前台页面,为其设置样式,代码如下:

<style type="text/css">
/* ASPnetBar淘宝风格 */
.paginator a {border:solid 1px #ccc;color:#0063dc;cursor:pointer;text-decoration:none;}
.paginator a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.paginator a:hover {border:solid 1px #F50;color:#f60;text-decoration:none;}
</style>

<div style=" font-size:12px; text-align :center ; width:700px ;color:#0063dc; padding:5px" >
          <webdiyer:AspNetPager ID="AspNetPager" CssClass="paginator"  runat="server" FirstPageText="首页" 
                        LastPageText="未页" NextPageText="下一页"
                        PrevPageText="上一页" ShowPageIndexBox="Always"              
               NumericButtonCount="5" 
               CenterCurrentPageButton="True"               
               HorizontalAlign="Center" Width="600px" 
            onpagechanged="AspNetPager_PageChanged" AlwaysShow="True">
               </webdiyer:AspNetPager>    
                </div>

后台绑定代码:

        /// <summary>
        /// GridView绑定全部数据
        /// </summary>
        public void GridViewBind()
        {
            txtRowCount.Text = newsManage.ExecuteScalar().ToString();
            AspNetPager.RecordCount = newsManage.ExecuteScalar();//数据访问层获得数据记录数
            int intStart = AspNetPager.PageSize * (AspNetPager.CurrentPageIndex - 1);
            int intNum = AspNetPager.PageSize;
            DataGridView.DataSource = newsManage.GetList(intStart, intNum);//返回数据列表
            DataGridView.DataBind();
        }

        protected void AspNetPager_PageChanged(object sender, EventArgs e)
        {
            try
            {
                GridViewBind();
            }
            catch (Exception ex)
            { throw ex; }
        }




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值