UWInfo Blog
發表新文章
[Join] | [忘記密碼] | [Login]
搜尋

搜尋意見
文章分類-#Author#
[所有文章分類]
所有文章分類
  • ASP.NET (48)
  • ASP.NET2.0 (15)
  • ASP.NET4.0 (34)
  • JavaScript (49)
  • jQuery (26)
  • FireFox (4)
  • UW系統設定 (3)
  • SQL (39)
  • SQL 2008 (25)
  • mirror (4)
  • SVN (4)
  • IE (9)
  • IIS (20)
  • IIS6 (1)
  • 閒聊 (7)
  • W3C (6)
  • 作業系統 (9)
  • C# (24)
  • CSS (12)
  • FileServer (1)
  • HTML 5 (11)
  • CKEditor (3)
  • UW.dll (13)
  • Visual Studio (16)
  • Browser (8)
  • SEO (1)
  • Google Apps (3)
  • 網站輔助系統 (4)
  • DNS (5)
  • SMTP (4)
  • 網管 (11)
  • 社群API (3)
  • SSL (4)
  • App_Inventor (1)
  • URLRewrite (2)
  • 開發工具 (6)
  • JSON (1)
  • Excel2007 (1)
  • 試題 (3)
  • LINQ (1)
  • bootstrap (0)
  • Vue (3)
  • IIS7 (3)
  • foodpanda (2)
  • 編碼 (2)
  • 資安 (3)
  • Sourcetree (1)
  • MAUI (1)
  • CMD (1)
  • my sql (1)
最新回應
  • Newtonsoft.Json.JsonConvert.DeserializeObject 失敗的情況
    test...more
  • dotnet ef dbcontext scaffold
    ...more
  • [ASP.NET] 利用 aspnet_regiis 加密 web.config
    ...more
  • IIS ARR (reverse proxy) 服務安裝
    ...more
  • [錯誤訊息] 請加入 ScriptResourceMapping 命名的 jquery (區分大小寫)
    ...more
  • 用 Javascript 跨網頁讀取 cookie (Cookie cross page, path of cookie)
    ...more
  • 線上客服 - MSN
    本人信箱被盜用以致資料外洩,是否可以請貴平台予以協助刪除該信箱之使用謝謝囉...more
  • 插入文字到游標或選取處
    aaaaa...more
  • IIS 配合 AD (Active Directory) 認証, 使用 .Net 6.0
    太感謝你了~~~你救了我被windows 認證卡了好幾天QQ...more
  • PostgreSQL 的 monitor trigger
    FOR EACH ROW 可能要改為 FOR EACH STATEMENT ...more
標籤
  • 專案 UNION A
  • 問題
  • ssl
  • t3jXryU8
  • Active
  • 9604
  • .,
  • -9935
  • VB轉C
  • ad
  • 50
  • vslerp
  • visual
  • request
  • async
  • vb轉c
  • ReportView
  • tmgZ0c1R
  • 復原
  • a
  • Data
  • en21211211
  • 444
  • mod[t]
  • 564
  • [t]
  • [U2]
  • let
  • 716
  • stop
  • ti
  • -9829 UNIO
  • 6342121121
  • request.fo
  • lazyload
  • exception
  • query
  • DTToExcelA
  • -8136
  • 104
  • download
  • 536
  • ef
  • JQ
  • load balan
  • 3644
  • minvalue
  • for ,
  • contains-t
  • 938
搜尋 template 結果:
MVC 的事件順序 (Base 和 Child 的工作)
ASP.Net MVC 如果只輸出字串的話, 可用的事件有: 目前前台規劃配合 Template, 在各事件中做以下的工作

BaseController Constructor
TestController Construtor
Base BeginExecute: 記錄 requestContext, 提供 GetRouteValue 使用.
Child BeginExecute:
Base Initialize:
Child Initialize: 可以在這裡設定 master Page 的檔名
Child BeginExecuteCore
Base BeginExecuteCore: this.otMaster = new UW.Template(MasterPage); 在這個之後才能使用 otMaster
Child CreateActionInvoker: InitTemplate("Index.html");  在這裡執行主要程式
Child OnAuthentication,
Base OnAuthentication
Child OnAuthorization 
Base OnAuthorization
Child OnActionExecuting
Base OnActionExecuting 最後整理 Template.

Child Index(): return this.FinalHTML;
More...
Bike, 2020/7/21 上午 10:58:12
jQquery 的 data 會刪除開頭的 0
<a class="del" href="#" data-yano="1250453286" data-pdno="04360003">
    <img src="/TC/template/Shopping/images/del.png" alt="">
</a>


用 $(".del").data("pdno") 會回傳 4360003
被這個搞了好久..

要避免這個問題, 可以使用 attr  來代替 data
$(".del").attr("data-pdno")
More...
Bike, 2017/6/13 下午 09:35:57
Post File With C#
Post 的資料好像會變大, 要改 Web.config
<system.web>
    <httpRuntime requestValidationMode="2.0" maxRequestLength="1024000"/>
</system.web>



程式碼如下:

public string UploadFilesToRemoteUrl(string url, string[] files, NameValueCollection formFields = null)
    {
        string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.ContentType = "multipart/form-data; boundary=" +
                                boundary;
        request.Method = "POST";
        request.KeepAlive = true;

        Stream memStream = new System.IO.MemoryStream();

        var boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" +
                                                                boundary + "\r\n");
        var endBoundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" +
                                                                    boundary + "--");


        string formdataTemplate = "\r\n--" + boundary +
                                    "\r\nContent-Disposition: form-data; name=\"{0}\";\r\n\r\n{1}";

        if (formFields != null)
        {
            foreach (string key in formFields.Keys)
            {
                string formitem = string.Format(formdataTemplate, key, formFields[key]);
                byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
                memStream.Write(formitembytes, 0, formitembytes.Length);
            }
        }

        string headerTemplate =
            "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
            "Content-Type: application/octet-stream\r\n\r\n";

        for (int i = 0; i < files.Length; i++)
        {
            memStream.Write(boundarybytes, 0, boundarybytes.Length);
            var header = string.Format(headerTemplate, "uplTheFile", files[i]);
            var headerbytes = System.Text.Encoding.UTF8.GetBytes(header);

            memStream.Write(headerbytes, 0, headerbytes.Length);

            using (var fileStream = new FileStream(files[i], FileMode.Open, FileAccess.Read))
            {
                var buffer = new byte[1024];
                var bytesRead = 0;
                while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                {
                    Response.Write("bytesRead: " + bytesRead.ToString() + "<br>");
                    memStream.Write(buffer, 0, bytesRead);
                }
            }
        }

        memStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
        request.ContentLength = memStream.Length;

        using (Stream requestStream = request.GetRequestStream())
        {
            memStream.Position = 0;
            byte[] tempBuffer = new byte[memStream.Length];
            memStream.Read(tempBuffer, 0, tempBuffer.Length);
            memStream.Close();
            requestStream.Write(tempBuffer, 0, tempBuffer.Length);
        }

        try
        {
            using (var response = request.GetResponse())
            {
                Stream stream2 = response.GetResponseStream();
                StreamReader reader2 = new StreamReader(stream2);
                return reader2.ReadToEnd();
            }
        }
        catch (Exception ex)
        {
            return (ex.ToString());
            throw;
        }
    }
More...
Bike, 2017/1/12 下午 08:21:09
在 PDF 加浮水印, 用 iTextSharp
找了兩三篇文章再加一點修正才組出來的,  記錄一下, 要用 iTextSharp 哦.

using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

---
 
            string oldFile = Server.MapPath("/Content/PDF/300000419_20160929162658862.pdf"); //"oldFile.pdf";
            string newFile = oldFile.Replace(".pdf", "_New11.pdf");

            // open the reader
            PdfReader reader = new PdfReader(oldFile);
            Rectangle size = reader.GetPageSizeWithRotation(1);
            Document document = new Document(size);
            int NumberOfPages = reader.NumberOfPages;

            // open the writer
            FileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write);
            PdfWriter writer = PdfWriter.GetInstance(document, fs);
            document.Open();

            // the pdf content
            PdfContentByte cb = writer.DirectContent;

            string text = "Watermark...";

            string windir = Environment.GetEnvironmentVariable("windir");
            Chunk textAsChunk = new Chunk(text, new Font(BaseFont.CreateFont(windir + "\\Fonts\\mingliu.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED), 20, Font.NORMAL, new BaseColor(255,0,0)));

            // create the new page and add it to the pdf
            for (int i = 1; i<= NumberOfPages; i++)
            {
                if(i > 1)
                {
                    document.NewPage();
                }

                ColumnText.ShowTextAligned(cb, Element.ALIGN_LEFT, new Phrase(textAsChunk), 0, 0, 0);

                PdfImportedPage page = writer.GetImportedPage(reader, i);
                cb.AddTemplate(page, 0, 0);
            }

            // close the streams and voilá the file should be changed :)
            document.Close();
            fs.Close();
            writer.Close();
            reader.Close();

            Response.Write(newFile + "<br>");
            Response.Write(NumberOfPages + "<br>");
More...
Bike, 2016/9/29 下午 06:23:59
UNT - UW.TBase 增加 strBodyTop 變數
由於偶爾會有需要在 <body> 最上方塞入一些 html
例如塞入一個要置頂的 div 區塊
目前這個區塊只有 {DebugMessage}

所以在 master.html 增加一個新的項目 叫做 <!--BodyTop--> 
<body>
    <!--BodyTop-->
    {DebugMessage}
    <a id="anchorGoTop" href="#gotop" class="gotop" style="display: none;"><span><em></em></span></a>

UW.TBase 增加一個 Public 變數  strBodyTop

如此一般網頁使用時 就可以置入置頂的內容 注意:是塞入html
使用上 於 PreRender 時
        '購物button區塊置於 <body> 正下方
        Me.strBodyTop = Me.otContent.SubTemplate("BuyButtonArea").Result
就可以了
 
More...
darren, 2014/6/20 上午 10:57:30
[程式片段][後台]VB懶惰版快取
        
'更新
        If UW.WU.IsNonEmptyFromQueryStringOrForm("Refresh") Then
            System.Web.HttpContext.Current.Cache.Remove(CacheName)
        End If
        '快取部分
        If obj Is Nothing Then
            Dim SQL As String = ""
            SQL = "select * from Product with (nolock)"
            obj = UW.SQL.DTFromSQL(SQL)

            Dim AC As New AggregateCacheDependency

            Dim DepArray() As CacheDependency = { _
                 New SqlCacheDependency(UW.SQL.sqlCacheDependencyName, "Product"), _
                 New SqlCacheDependency(UW.SQL.sqlCacheDependencyName, "Product_Category") _
            }

            AC.Add(DepArray)
            Dim FD As New CacheDependency(UW.Template.TemplateRoot & "2013UI\Product\DirectBuyAllProduct.html")
            AC.Add(FD)

            System.Web.HttpContext.Current.Cache.Insert(CacheName, obj, AC)

        End If
More...
Doug, 2014/1/15 下午 02:12:27
IndexOf 效能問題
一直覺得 UW.Template 應該還有改善的空間,因為網站大量使用這個物件
只要有一些些效能調教,對於整體效能應該有很大的幫助

昨天發現切版的程式 UW.Template => GetTemplateFromString
在使用 IndexOf 去尋找 <!--Key S--> 及 <!--Key E--> 時,
<!--Key E--> 可能有一些問題,因為他是從第0個位置開始找
而實際上他應該是從 <!--Key S--> 後面開始找比較對
所以後者的 IndexOf 要加個 StartIndex 參數值比較對


    StartP = StartP + StartKey.Length
    Dim EndP As String = Source.IndexOf(EndKey, StringComparison.OrdinalIgnoreCase)
    ' 應該修改為以下寫法 =>
    StartP = StartP + StartKey.Length
    Dim EndP As String = Source.IndexOf(EndKey, StartP, StringComparison.OrdinalIgnoreCase)    


另外 我也針對 StringComparison 做一些測試 
然後以一個 20KB 的 html 去抓出 <!--Content E--> 的位置
測試結果如下 (StartP 是 <!--Content S--> 後的起始位置)


0.0005085 No StartP
0.0002082 with StartP
0.0000157 StringComparison.Ordinal with StartP
0.0002768 StringComparison.OrdinalIgnoreCase, No StartP
0.0001105 StringComparison.OrdinalIgnoreCase with StartP
0.0002116 StringComparison.CurrentCulture with StartP
0.0002085 StringComparison.CurrentCultureIgnoreCase with StartP


結論: 
1. IndexOf 預設是以 StringComparison.CurrentCulture 方式尋找字串
2. 對於大塊字串,請盡量用 StartP 去找結束標籤位置,這樣速度會快很多,因為少爬了一段文字,此範例是差了2.5倍
3. 對於大塊字串,除非大小寫都要找,不然盡量用 StringComparison.Ordinal 來尋找字串,速度差了7~8倍

微軟對於.NET字串處理 有一篇建議文章,請大家拜讀一下
http://msdn.microsoft.com/zh-tw/library/vstudio/dd465121(v=vs.100).aspx
More...
darren, 2014/1/14 下午 03:18:14
Template 中新增 IsDefaultNewVersion
IsDefaultNewVersion 設為 true 時, 要改用 { } 來標記變數.
More...
Bike, 2012/6/14 下午 06:53:43
UW.LM 翻譯物件
hi:
我在 UW 4.0 附上之前做的翻譯物件,使用方法在附檔裡
基本上是把拆解網頁文字翻譯內容放在xml文字檔裡面
這是以一般ASP.NET開發方式用Server Control來處理
用 AutoTranlate 可以很快取代所有文字,不用一個一個取代
但是遇到我們Template物件,就不能用啦
這部分我再調一下,讓 Template物件也能夠 AutoTranlate
More...
darren, 2012/6/5 下午 07:53:16
~ Uwinfo ~