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
標籤
  • CS
  • iis
  • date order
  • vs
  • 4987
  • images
  • shop212112
  • z-index
  • 7404
  • jq
  • 1602
  • �
  • ajax,
  • 複製21211211
  • 98
  • 12
  • 992
  • 時間
  • XML
  • 70
  • .
  • win
  • User
  • 網站
  • 0
  • 版本
  • 1222121121
  • 指令
  • [u2]
  • a
  • 308
  • @@26E64
  • 火狐
  • -3968
  • 20
  • validation
  • 考試
  • visual
  • 80
  • amazone
  • 14
  • entify
  • primary
  • [t]
  • 還原
  • 270
  • PAY
  • 364
  • trigger
  • ti
頁數 2 / 3 上一頁 下一頁
搜尋 response 結果:
轉整數的方法需注意的地方
比較特別的地方,都在下面的程式碼後面的註解
​
Response.Write(Convert.ToInt32("94"));
Response.Write("<br/>");
Response.Write(Convert.ToInt32(94.5)); //會四捨六入五成雙
Response.Write("<br/>");
Response.Write((94.5).ToString("N0")); //會四捨五入
Response.Write("<br/>");
Response.Write((95.5).ToString("N0")); //會四捨五入
Response.Write("<br/>");
Response.Write(Convert.ToInt32(null)); //會 return 0
Response.Write("<br/>");
Response.Write(Convert.ToInt32("94.55")); //會有 exception 要先轉成 double 之類的數值
Response.Write("<br/>");
More...
darren, 2017/3/27 上午 10:47:25
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
簡單的 HTTP Relay By MVC.
客戶要求
1. 檔案只能放在 Firewall 內的後台用 Web server (Server A).
2. 使用者只能存取 DMZ 的 Web server (Server B).
3. Server B 只能用 HTTP 通過 Firewall 向 Server A 要資料.(i.e.  Server B 不能掛戴 Server A 的目錄成為虛擬目錄)

所以在 Server B 上面建立了一支程式用 HTTP 的方式讀取 Server A 的檔案再寫出去.

例如, http://ServerB/Upload/test.pdf 會讀取 http://ServerA/Upload/test.pdf 再送到 Client 端

namespace WWW.Controllers
{
    public class UploadController : Controller
    {
        // GET: Upload
        public void Index(string Filename)
        {
            //Create a stream for the file
            Stream stream = null;

            //This controls how many bytes to read at a time and send to the client
            int bytesToRead = 10000;

            // Buffer to read bytes in chunk size specified above
            byte[] buffer = new Byte[bytesToRead];

            string url = "http://admin-dev.nanya.bike.idv.tw/newnanyaback/Upload/" + Filename;

            // The number of bytes read
            try
            {
                //Create a WebRequest to get the file
                HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(url);

                //Create a response for this request
                HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();

                if (fileReq.ContentLength > 0)
                    fileResp.ContentLength = fileReq.ContentLength;

                //Get the Stream returned from the response
                stream = fileResp.GetResponseStream();

                // prepare the response to the client. resp is the client Response
                var resp = HttpContext.Response;

                if (Filename.ToLower().EndsWith(".png") ||
                    Filename.ToLower().EndsWith(".jpg") ||
                    Filename.ToLower().EndsWith(".jpeg") ||
                    Filename.ToLower().EndsWith(".gif")
                    )
                {
                    resp.ContentType = "image";
                }
                else
                {
                    //Indicate the type of data being sent
                    resp.ContentType = "application/octet-stream";

                    //Name the file
                    resp.AddHeader("Content-Disposition", "attachment; filename=\"" + HttpUtility.UrlEncode(Filename, Encoding.UTF8) + "\"");
                }

                resp.AddHeader("Content-Length", fileResp.ContentLength.ToString());

                int length;
                do
                {
                    // Verify that the client is connected.
                    if (resp.IsClientConnected)
                    {
                        // Read data into the buffer.
                        length = stream.Read(buffer, 0, bytesToRead);

                        // and write it out to the response's output stream
                        resp.OutputStream.Write(buffer, 0, length);

                        // Flush the data
                        resp.Flush();

                        //Clear the buffer
                        buffer = new Byte[bytesToRead];
                    }
                    else
                    {
                        // cancel the download if client has disconnected
                        length = -1;
                    }
                } while (length > 0); //Repeat until no data is read
            }
            finally
            {
                if (stream != null)
                {
                    //Close the input stream
                    stream.Close();
                }
            }
        }
    }
}



但不是這樣就好了, 在 RouteConfig.cs 中要加上:
            routes.MapRoute(
                name: "Upload",
                url: "Upload/{filename}",
                defaults: new { controller = "Upload", action = "Index", filename = UrlParameter.Optional }
            );

此外在 Web.Config 中也要加上:

  <system.webServer>
    <handlers>
      <add name="UrlRoutingHandler_Upload"
           type="System.Web.Routing.UrlRoutingHandler, 
               System.Web, Version=4.0.0.0, 
               Culture=neutral, 
               PublicKeyToken=b03f5f7f11d50a3a"
           path="/Upload/*"
           verb="GET"/>
    </handlers>
  </system.webServer>

參考:
http://stackoverflow.com/questions/5596747/download-stream-file-from-url-asp-net

http://blog.darkthread.net/post-2014-12-05-mvc-routing-for-url-with-filename.aspx
More...
Bike, 2016/12/1 下午 09:34:30
在 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
資料前後端傳遞回顧
在做地址的時候用了一個套件(TWZIPCODE)
可以幫你產生下拉霸的郵遞區號選項
很方便(jQuery)
但是在控制他的資料及回傳
又不知道怎樣比較方便直觀了

首先目前也是文字控制的方式是
UWForUNT.WU.ReplaceStringInControl(Me.Page, "#Post_Code#", Post_Code)
直接用 #Post_Code#
再把她取代

直接讓前端讀到值

回傳時 若是用後端控制 不用再傳ajax 或是 塞到別的後端控制項
回傳的方式
UW.WU.GetValueFromQueryStringOrForm("Post_Code")

但是因為之後不讓 Page Load 再次改成預設值
可以加
If Not Me.IsPostBack Then
   UW.WU.GetValueFromQueryStringOrForm("Post_Code")
End If
才不會永遠是預設值
(            $('#twzipcode').twzipcode({
            zipcodeSel: '#Post_Code#', // 此參數會優先於 countySel, districtSel
            countySel: '台北市',
            districtSel: '大安區',
            zipcodeName: 'Post_Code'
            })
)

他如果有包在裡可以直接讀取

另外若是 有一些後端要傳給前端的資料 用response.Write("<script>XXX</script>")
可以直接寫入前端
More...
sean, 2014/11/27 下午 04:20:42
新版Chrome location.reload() 問題
location.reload()

Chrome 最新的版本 
會把 本來的表單重送,所以我在 
UW.WU.ShowMessageAndRefresh 
 
System.Web.HttpContext.Current.Response.Write("location.reload()" & vbCrLf)

更改為
System.Web.HttpContext.Current.Response.Write("location.href=location.href" & vbCrLf)


 
More...
瞇瞇, 2014/10/20 下午 03:17:32
304 和 200 (From Cache)
今天在觀察 Chrome 怎麼處理網頁中的 <script type="text/javascript" src="/scripts/unt.14.04.10.19.05.42.js"></script>  時,終於明白何時才會 200 (From Cache) (unt.14.04.10.19.05.42.js 是假的,實際會被重導到 scripts.aspx 來處理。)

1. 在網址列,同網址再按一下  Enter 載入時,Chrome 會對相同的網址再次送出 request。

2. 若是點選頁面中的連結或是在網址列輸入其它網址,才有可能看到 200 (From Cache)

在情況 1 時,若是有使用 Response.Cache.SetLastModified(Now) 則會看到 304 ,否則會把 Script 重新載入一次。

所以在 Server 最佳的(我覺得)寫法是:

Response.Cache.SetCacheability(HttpCacheability.Private)
Response.Cache.SetExpires(Now.AddYears(1))  '一年後才會到期,沒有這個就不會有 200 (From Cache)
Response.Cache.SetLastModified(Now)  '若是 Browser 送出了一個新的 Request, 有可能會回 304


不過有趣的是,在 scripts.aspx 收到帶有 ​If-Modified-Since 的 Request 時,是怎麼判斷要回應 304 的,我在 .vb 裡面沒有加上這個處理吔。
More...
Bike, 2014/4/10 下午 07:38:01
使用 facebook JS SDK 的心得筆記
以前只是用 facebook 的server端 API 來處理登入
這次因為活動關係而純粹使用 JS SDK 來處理 user 的發文
這裡把一些用到 function 作整理
比較特別的是 FB.login 使用時機,因為他會 window.open 新視窗
若是 ajax 資料後再呼叫,通常會被瀏覽器檔下來
使用時機最好是user點了button後就直接執行
//先檢查是不是已經登入
FB.getLoginStatus(function (response) {
    if (response.status === "connected") {
    // 已登入FB
    }
else {
        // 未登入FB
        // 盡量不要在此呼叫 FB.login , 因為彈跳視窗會被擋下來
}
});

//呼叫登入 scope:publish_stream 是要讓user同意發文到FB的權限
FB.login(function (response) {
    if (response.authResponse) {
        // 已登入,可取得 AccessToken
    } else {
        // 未登入
    }
}, { scope: 'publish_stream' });

// 檢查 user 有無同意發文到FB的權限 (publish_stream)
FB.api({ method: 'users.hasAppPermission', ext_perm: 'publish_stream' }, function (resp) {
    if (resp === "1") {
        //有同意
    } else {
        //不同意
    }
});

// 分享連結到登入者的FB牆
// msg 是發文的內容
// link, picture, caption, description 是一組的
var args = {
    message: msg,
    link: product.Link,
    picture: product.Picture,
    caption: product.Name,
    description: "超高口碑BB霜/CC霜、頂級精華液哪款半價 由你決定!"
};
FB.api('/me/feed', 'post', args, function (response) {
    if (response.id) {
        // 成功會回傳訊息id
    }
    else {
        // 分享失敗
    }
});


再補充一下,若只是單純分享網頁,可以使用 FB.ui,就不用管有無登入以及權限問題

    FB.ui({
        method: 'feed',
        name: '快去搶!超過9成的使用者滿意推薦的《玻尿酸精華》',
        link: 'http://www.shopunt.com/tch/event/2014-aqua-deluge/default.aspx',
        picture: 'http://www.shopunt.com/Upload/tch/unt/14mar/fb154x154.jpg',
        caption: 'UNT 頂級玻尿酸保濕精華液(奢華)',
        description: '熱銷破百萬 真實口碑見證的水感奇肌 逆時補水科技 快速滲透 為肌膚注入高水位……'
    },
        function (response) {
            if (response && response.post_id) {
                // handle  success
            }
            else {
                alert("facebook分享失敗!");
            }
        }
    );
More...
darren, 2014/3/3 上午 10:06:40
[程式片段][前台]VB預設
    
    Inherits Master
    Protected Sub Page_PreLoad(sender As Object, e As EventArgs) Handles Me.PreLoad
    End Sub

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        HandleAction()
    End Sub

    Sub HandleAction()
        If UW.WU.IsNonEmptyFromQueryStringOrForm("Action") Then
            Dim Action As String = UW.WU.GetValueFromQueryStringOrForm("Action")
            Select Case Action
            End Select
        End If
    End Sub

    Protected Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
        LoadPageContext()
    End Sub

    Sub LoadPageContext()

    End Sub

    Sub JSONWriteToClient(ByVal TrueorFalse As Boolean, Optional ByVal msg As String = "", Optional ByVal Title As String = "", Optional ByVal Content As String = "", Optional ByVal Content2 As String = "", Optional ByVal Content3 As String = "")
        Dim TF As String = Now.ToString("yyyyMMddHHmmss")
        Dim oJ As UW.JSON
        oJ = New UW.JSON(TrueorFalse, msg)
        oJ.add("Title", Title)
        oJ.add("Content", Content)
        oJ.add("Content2", Content2)
        oJ.add("Content3", Content3)
        oJ.add("TF", TF)
        oJ.WriteToClient()
        Response.End()
    End Sub
More...
Doug, 2014/1/6 下午 12:25:22
Global 網站使用 CultureInfo 物件
製作 Global 網站時,由於User來自世界各地
而各地對於時間格式以及貨幣,數字顯示方式都有所不同
這時就需要 .NET Globalization -> CultureInfo 來處理這個問題
CultureInfo 是基於 Language Code 來的
而 user 的 Language Code 基本上瀏覽器會放在 Request Header 送到Server
(ex. Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4)

        Dim d As Date = Now
        Dim n As Decimal = 86400.99
        Dim Cultures() As String = {"zh-TW", "pt-BR", "pt-PT", "en-US", "en-GB", "fr-FR", "de-DE", "es-ES", "ja-JP", "zh-CN", "ko-KR", "en-IN"}
        For i As Integer = 0 To Cultures.GetUpperBound(0)
            Dim c As New Globalization.CultureInfo(Cultures(i))
            Response.Write(Cultures(i) & "<br/>" & d.ToString("D", c) & " <br/>" & d.ToString("d", c) & "<br/>" & n.ToString("C", c))
            Response.Write("<hr/>")
        Next


結果如下:

zh-TW
2013年12月25日
2013/12/25
NT$86,400.99

pt-BR
quarta-feira, 25 de dezembro de 2013
25/12/2013
R$ 86.400,99

pt-PT
quarta-feira, 25 de Dezembro de 2013
25-12-2013
86.400,99 €

en-US
Wednesday, December 25, 2013
12/25/2013
$86,400.99

en-GB
25 December 2013
25/12/2013
£86,400.99

fr-FR
mercredi 25 décembre 2013
25/12/2013
86 400,99 €

de-DE
Mittwoch, 25. Dezember 2013
25.12.2013
86.400,99 €

es-ES
miércoles, 25 de diciembre de 2013
25/12/2013
86.400,99 €

ja-JP
2013年12月25日
2013/12/25
¥86,401

zh-CN
2013年12月25日
2013/12/25
¥86,400.99

ko-KR
2013년 12월 25일 수요일
2013-12-25
₩86,401

en-IN
25 December 2013
25-12-2013
₹ 86,400.99
More...
darren, 2013/12/26 下午 04:04:39
|< 123 >|
頁數 2 / 3 上一頁 下一頁
~ Uwinfo ~