2016年5月24日 星期二

[azure]靜態頁放置在Micrsoft Azure 雲端空間

首先,要先用信用卡註冊一個可使用免費ㄧ個月的帳號
https://azure.microsoft.com/zh-tw/free/


 接著進入azure https://portal.azure.com/ 

點選 +新增 > Web+行動 > Web應用程式
因為範例是放網頁靜態頁 所以我選Web應用程式


填入資料 按建立


設定部屬認證 

這裡填入的帳號密碼,是若使用FTP/Git上傳檔案時使用




發佈網站

回到Visual Studio , 打開欲發行的專案 > 建置 > 發行























發行成功,會自動跳出你發行的網站

網址是 xxx.azurewebsites.net

xxx是你自行填入的應用程式名稱


2016年5月11日 星期三

[JS]判斷瀏覽器 navigator.userAgent

function isMobile() {
         //   return true;
        if (isMobiles.any()) {
            return true;
        } else {
            return false;
        }
    }

var isMobiles = {
        Android: function () {
            return navigator.userAgent.match(/Android/i);
        },
        BlackBerry: function () {
            return navigator.userAgent.match(/BlackBerry/i);
        },
        iOS: function () {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i);
        },
        Opera: function () {
            return navigator.userAgent.match(/Opera Mini/i);
        },
        Windows: function () {
            return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i);
        },
        any: function () {
            return (isMobiles.Android() || isMobiles.BlackBerry() || isMobiles.iOS() || isMobiles.Opera() 
                   || isMobiles.Windows());
        },
        FB: function () {
            return navigator.userAgent.match(/FB/i);
        },
        FBIOS: function () {
            return navigator.userAgent.match(/FBIOS/i);
        }
    };

function PostFB() {
      try {
          if (isMobile()) {
              shareurl = "https://www.facebook.com/dialog/feed?app_id=' + MyappID 
                            + '&display=touch&caption=Mycaption&link=http%3A%2F%2Fwww.google.com.tw&picture=' 
                            + MyPictireLink + '&redirect_uri=' + Myredirect +'&description=Mydescription";
              window.open(shareurl);
              location.href = 'http://www.google.com';
          }
          else 
          {
              FB.ui({
                  method: 'feed',
                  link: 'http://www.google.com',
                  caption: '#',
                  redirect_uri: 'http://www.google.com',
                  picture: MyPictureLink,
                  name: 'name',
                  message: 'message',
                  description: 'description',
              }, function (response) {
                  if(response == undefined){
                //...do something
               }
               else{
                //...do something
               }
              });
          }

[MVC] 簡易分頁 PagedList

1. 先安裝 NuGet套件 - PagedList.Mvc



























2. Controller

      using PagedList;
      using PageList.Models;

        public ActionResult Index(int page =1)
        {
            //page用來記憶目前是哪一頁
            int currentPage = page < 1 ? 1 : page;

           //資料必須先經過排序
            var product = db.Product.Where(x => x.Status == 1).OrderBy(x => x.ID);

            //分頁資料使用 ToPagedList()
            //參數分別是傳入所要分頁的頁碼以及分頁資料量
            //此範例就是每一頁會有10筆資料
            var PageResult = product.ToPagedList(currentPage, 10);
            

            return View(PageResult);
        }

3. View
















需要using PagedList.Mvc PagedList

取得分頁:

@Html.PagedListPager((IPagedList)Model, page => Url.Action("Index", new { page = page}))


































//設定PagedListRenderOptions 可更改樣式
@Html.PagedListPager((IPagedList)Model, page => Url.Action("Index", new  { page = page})
,PagedListRenderOptions.MinimalWithPageCountText)



//也可以自由設定顯示物件
@Html.PagedListPager((IPagedList)Model, page => Url.Action("Index", new  { page = page}),
    new PagedListRenderOptions {
        DisplayLinkToIndividualPages=false,
        DisplayLinkToFirstPage =PagedListDisplayMode.IfNeeded,
        DisplayLinkToLastPage= PagedListDisplayMode.IfNeeded,
        DisplayLinkToNextPage = PagedListDisplayMode.IfNeeded,
        DisplayLinkToPreviousPage = PagedListDisplayMode.IfNeeded,
        DisplayPageCountAndCurrentLocation = true,
        PageCountAndCurrentLocationFormat ="第{0}頁 / 共{1}頁"
    })









https://github.com/TroyGoode/PagedList

2016年5月5日 星期四

[JS]上傳檔案大小限制

因為沒限制檔案上傳大小
所以發生了一些美麗的誤會~~~ T_T
發了此篇,以謹記在心
var size = document.getElementById("file").files.item(0).size;

if (size > 10240000) {
    alert("上傳檔案請小於 10M");
    return false;
  }

2016年5月3日 星期二

[C#][EXIFextractor] Mobile Web 上傳圖片,照片翻轉90度 rotateImage


遇到這種問題 有點傻眼

不知道怎麼解決,測了也沒發現什麼規律性的原因(偏偏我就是拿偏偏我就是用iphone safari)

頓時有了希望全世界都生活在智障型手機的時代是多麼美好,多麼幸福,多麼......方便 ORZ

不過感嘆歸感嘆,希望歸希望,身為21世紀現代人類,還是要追求一下科技進步、社會發展



不用你們提醒我,我知道我現在很難得的正在囉嗦.............

[問題原因] 貌似是瀏覽器吃不到照片的一些tag

這裡有針對IOS詳細介紹照片方向的問題

解決之前 還要加入參考

點我連結下載頁面  進去之後點 Donload Source files

code在這

方便大家 也為了防止頁面被404狙擊 我還是備份一下



HttpPostedFile file = HttpContext.Current.Request.Files["file"];
 
//Create bitmap image from posted file
System.Drawing.Bitmap bmpImg = new System.Drawing.Bitmap(file.InputStream);
 
//rotate if needed
bmpImg = rotateImage(bmpImg);
 
//save image
targetFilePath = "somewhere...";
bmpImg.Save(targetFilePath, ImageFormat.Jpeg);
public Bitmap rotateImage(System.Drawing.Bitmap img)
    {
        try
            {
                RotateFlipType rft = RotateFlipType.RotateNoneFlipNone;
                System.Drawing.Imaging.PropertyItem[] properties = img.PropertyItems;
                
                foreach (System.Drawing.Imaging.PropertyItem p in properties)
                {
                    if (p.Id == 274 || p.Id == 5029)
                    {
                        short orientation = BitConverter.ToInt16(p.Value, 0);
                        switch (orientation)
                        {
                            case 1:
                                rft = RotateFlipType.RotateNoneFlipNone;
                                break;
                            case 3:
                                rft = RotateFlipType.Rotate180FlipNone;
                                break;
                            case 6:
                                rft = RotateFlipType.Rotate90FlipNone;
                                break;
                            case 8:
                                rft = RotateFlipType.Rotate270FlipNone;
                                break;
                        }
                    }
                }
                if (rft != RotateFlipType.RotateNoneFlipNone)
                {
                    img.RotateFlip(rft);
                }
            }
            catch
            {

            }
            return img;
    }