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
標籤
  • -6396
  • doug
  • IP
  • .
  • LISTENING
  • 問題
  • dot ef
  • 低安全性
  • uw
  • Json.NET
  • tmgZ0c1R
  • 494
  • isnull
  • 102
  • sql accoun
  • https:1684
  • 1341
  • 6996
  • 70
  • 使用者
  • 貨幣
  • -5615 ORDE
  • 174
  • Windows 20
  • inline
  • images
  • DB
  • 696
  • 專案
  • 28
  • -3968
  • viewstate
  • 56
  • mod
  • 100
  • Data
  • 88 ORDER B
  • -2154 UNIO
  • server
  • 8.5Oucg
  • groupby
  • Message
  • 18
  • 62
  • newid
  • IIS6
  • shop order
  • inertSQL
  • needlock
  • sw
頁數 2 / 2 上一頁
搜尋 使用者 結果:
簡單的 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
Server端的時區轉換
之前作的 MaskQueen專案 以及現在 UNT的TR獨立專案
都牽涉到後台使用者及前台User看訂單時間錯誤問題
因為系統時間是TW的時間而操作者是外國的使用者 這就需要有個方便模組來轉換系統時間以及user的時間顯示

這部分我以 Extension Method 方式來處理
in VB
Imports System.Runtime.CompilerServices
Imports Microsoft.VisualBasic
 
Public Module DateTimeExtension
 
    ''' <summary>
    ''' 將系統時間轉為當地的時間並轉為字串
    ''' </summary>
    ''' <param name="dtSystem"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Extension()> _
    Public Function ToCountryDateTimeString(ByVal dtSystem As DateTime) As String
 
        If dtSystem = DateTime.MinValue Then
            Return "n/a"
        End If
        Dim cstTime As DateTime = dtSystem.ToCountryDateTime()
        ' tr-TR -> dd.MM.yyyy HH:mm:ss
        Dim langCode As String = SHOPUNT.DB.SysConfig.GetSysConfig("DefaultLangCode")
        Dim culture As New System.Globalization.CultureInfo(langCode)
        If cstTime.AddMonths(6) < Now Then
            Return cstTime.ToString("dd.MM.yyyy HH:mm", culture)
        Else
            Return cstTime.ToString("dd.MMM HH:mm", culture)
        End If
 
    End Function
 
    ''' <summary>
    ''' 將系統時間轉為當地的時間
    ''' </summary>
    ''' <param name="dtSystem"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Extension()> _
    Public Function ToCountryDateTime(ByVal dtSystem As DateTime) As DateTime
        Dim cstZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(SHOPUNT.DB.SysConfig.GetSysConfig("DefaultTimeZone"))
        Dim localZone As TimeZoneInfo = TimeZoneInfo.Local
        Dim cstTime As DateTime = TimeZoneInfo.ConvertTime(dtSystem, localZone, cstZone)
        Return cstTime
    End Function
 
    ''' <summary>
    ''' 將使用者輸入的時間轉為系統時間
    ''' </summary>
    ''' <param name="dtCountry"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Extension()> _
    Public Function ToSystemDateTime(ByVal dtCountry As DateTime) As DateTime
        Dim cstZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(SHOPUNT.DB.SysConfig.GetSysConfig("DefaultTimeZone"))
        Dim localZone As TimeZoneInfo = TimeZoneInfo.Local
        Dim sysTime As DateTime = TimeZoneInfo.ConvertTime(dtCountry, cstZone, localZone)
        Return sysTime
    End Function
 
End Module
使用上 只要
DateTime.Now.ToCountryDateTime() 就可以把系統時間轉換成user時間
相反的也有把 user時間轉換成系統時間的功能 ToSystemDateTime()

英國的TimeZone: GMT Stanard Time
Turkey的TimeZone: Turkey Stanard Time
以上的值可以用 TimeZoneInfo.GetSystemTimeZones() 找出來
More...
darren, 2014/5/2 下午 12:27:18
開放備份資料庫的權限
想要讓特定 user 可以備份某個 DB ,但又不想把該 user 加入 sysadmin 時,可以用的。

use DBName
GRANT BACKUP DATABASE TO uasername

接下來該使用者的帳戶就可以執行
​
BACKUP DATABASE XXX TO DISK = 'D:\SQLBackup\XXXXX.bak'
More...
Bike, 2014/4/3 下午 04:07:47
SQL Server log 檔案過大
參考來源:http://seasuwang.blogspot.tw/2009/09/sql-server-log.html

SQL Server 2008 Transcation log 檔案太大,導致SQL Server無法運作
將SQL Server的執行程序停止,手動刪除log實體檔案,再次啟動SQL Server的程序,資料庫沒辦法work

參考 Seasu Wang 說明把資料庫給救回來,步驟如下:
假設資料庫名稱為OhMyGod
1. 停止SQL Server, 將原mdf檔移走
2. 開啟SQL Server, 建立新的OhMyGod資料庫.
3. 停止SQL Server
4. 將損壞的mdf覆蓋回新建的mdf檔,並刪除新建的log檔
5. 開啟SQL Server
3. 設定OhMyGod資料庫狀態為EMERGENCY:
ALTER DATABASE OhMyGod SET EMERGENCY
4. 設定OhMyGod資料庫模式為"單一使用者":
sp_dboption 'OhMyGod', 'single user', 'true'
5. 檢查指定資料庫中所有物件的配置、結構和邏輯完整性:
DBCC CHECKDB (OhMyGod, REPAIR_ALLOW_DATA_LOSS)
6. 還原OhMyGod資料庫模式:
sp_dboption 'OhMyGod', 'single user', 'false'
7. 設定OhMyGod資料庫狀態為
ONLINE:ALTER DATABASE OhMyGod SET ONLINE
 
More...
Reiko, 2014/3/21 上午 11:52:10
windows檔案權限修改
公司有些人需要到特定主機做測試之類的,這時需要改windows系統的hosts檔案,由於hosts是系統檔,必須要有編輯權限才能編輯,所以這次教大家如何更改檔案權限。

首先先到要修改的檔案位置,在檔案下按右鍵選"內容"如下圖


接著按下"安全性"如圖


在群組或使用者名稱下選擇users會發現system權限只有讀取跟執行,如圖


這時,按一下右下的按鈕"編輯"進入編輯模式後,再選擇users,如圖


在users的權限下,點選"完全控制"後,再點"套用"或"確定",
即可將此檔案內容做修改,如圖


PS. 通常在幫domain使用者修改系統動作時,會需要管理者密碼,所以會有以下兩種情況發生:
1. 當修改檔案為"完全控制"時,若跳出輸入管理者帳號密碼視窗,此時輸入後即可完成權限修改,再對此檔案做修改。
2. 當修改檔案為"完全控制"時,若跳出無法修改的視窗,這時需要先登入電腦到管理者帳號,再到此檔案(如hosts),
   按照剛剛上述的步驟操作修改權限,完成之後。再登入原先使用者帳號,再對此檔案做修改。






 
More...
nelson, 2014/3/6 上午 10:56:22
使用 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
SQL 2008 Express安裝問題
參考:Microsoft® SQL Server® 2008 Express安裝步驟指南

※Microsoft® SQL Server® 2008 Express with Tools此版本才有管理工具。

必備元件

Microsoft .NET Framework 3.5 Service pack 1(不裝連安裝畫面都無法開啟)
http://www.microsoft.com/downloads/details.aspx?FamilyId=AB99342F-5D1A-413D-8319-81DA479AB0D7&displaylang=zh-tw


Windows Installer 4.5 Redistributable - 繁體中文(不安裝就無法安裝SQL Server 2008)
http://www.microsoft.com/downloads/details.aspx?displaylang=zh-tw&FamilyID=5a58b56f-60b6-4412-95b9-54d056d6f9f4

PowerShell 1.0(不裝在檢查元件步驟就無法通過)
926139:Windows PowerShell 1.0 英文語言安裝封裝適用於 Windows Server 2003 及 Windows XP
926140:Windows Server 2003 Service Pack 1 與 Windows XP Service Pack 2 的 Windows PowerShell 1.0 當地語系化安裝套件
926141:Windows 1.0 PowerShell 多語系使用者語言介面 (MUI) Pack 適用於 Windows Server 2003 或適用於 Windows XP
928439:適用於 Windows Vista 的 Windows PowerShell 1.0 安裝封裝




※MSXML 6 SP2 會造成 SQL Server 2008 安裝失敗
解:先移除掉 MSXML 6 SP2,安裝完 SQL Server  2008 後,再更新 HotFix 一次
http://byronhu.wordpress.com/2008/12/25/msxml-6-sp2-%E6%9C%83%E9%80%A0%E6%88%90-sql-server-2008-%E5%AE%89%E8%A3%9D%E5%A4%B1%E6%95%97/


More...
Reiko, 2012/10/16 下午 01:00:50
virtual directory 的執行權限
在 IIS 7.0 網站下掛入的 virtual directory 預設是可以執行指令碼的,所以若是使用者上傳了 aspx, 那該 aspx 就可以執行.. 這會是一個很大的安全問題. 要解決這個, 必需在該目錄的處理常式對應中,把指令碼的功能取消. 看來又要做一次大檢查了.

1. 處理常式對應:

 

2. 編輯功能權限,並且把指令碼拿掉。
 


More...
Bike, 2012/7/30 下午 12:02:17
便用非管理者帳戶來執行網站, 會遇到載入 DLL 的問題 -- 無法載入檔案或組件 XXX 或其相依性的其中之一。 存在某個不正常的 API 呼叫。
我今天試著建立一個一般的使用者帳號來執行某個網站 (<identity impersonate="true" userName="XXX" password="abcdefg"/>) , 遇到以下的問題, 結果把該使用者加入 IIS_IUSRS 就 OK 了.

無法載入檔案或組件 'FredCK.FCKeditorV2' 或其相依性的其中之一。 存在某個不正常的 API 呼叫。 (發生例外狀況於 HRESULT: 0x800300FA (STG_E_ABNORMALAPIEXIT))

 
More...
Bike, 2012/6/9 上午 08:26:48
|< 12 >|
頁數 2 / 2 上一頁
~ Uwinfo ~