Archive for the 'Tip Dev' Category


วิธีแก้ไข ASP.NET C# เมื่อ Rename หรือ Delete Folder แล้ว Session Timeout

บันทึกโดย TaTump วันที่ 25 June 2010 | 270 views

นั่งเสียเวลาเป็นชม.ๆ –” มันอะไรกันนักหนาเนี่ย 55+ ไปได้วิธีมาจากเว็บ Narisa และ Greatfriends ได้ความว่า ใน ASP.NET 2.0 ได้เพิ่มสิ่งที่เรียกว่า File Change Notifications (FCN) หรือ Directory Monitoring เพื่อคอยจับ Directory ทุกครั้งที่มีการ Rename หรือ Delete มันจะ Restart Application ดังนั้น Session State ที่เก็บแบบ InProc จะหายไปด้วย (เออเอากับมัน…)

เกริ่นซะยาวมาดูวิธีแก้กันเลยให้ใส่ Code ด้านล่างนี้ ในไฟล์ “Global.asax.cs” ที่ Events Application_Start() และใช้ using System.Reflection ด้วย ซึ่งการทำงานของมันจะปิด Directory Monitoring ทันทีที่ Application เริ่มทำงาน

System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
object o = p.GetValue(null, null);
System.Reflection.FieldInfo f = o.GetType().GetField("_dirMonSubdirs", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
System.Reflection.MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { });

สำหรับคนที่ยังไม่เคยใช้ Global.asax.cs ขออธิบายนิดนึงครับ

ไฟล์ Global.asax.cs จะมีไฟล์ Global.asax Inherits มาเรียกอีกทีนึง และทั้งสองไฟล์จะต้องอยู่บนสุดของเว็บไซต์เท่านั้นนะจ๊ะ ยิ่งอธิบายยิ่ง”งง” ดาวน์โหลดไปเลยดีกว่าตรงนี้ผมใส่ Code ด้านบนไว้ให้เรียบร้อยแล้วครับ
คลิกที่นี่เพื่อดาวน์โหลด Global.asax และ Global.asax.cs

เมื่อเราใส่ Code เรียบร้อยแล้วหากเกิดกรณี Error ประมาณนี้


Security Exception
Description: The application attempted to perform an  operation not allowed by the security policy.  To grant this  application the required permission please contact your system  administrator or change the application's trust level in the  configuration file.
 Exception Details: System.Security.SecurityException:  Request failed.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

ให้ไปที่ไฟล์ web.config แล้วไปเพิ่มตาม Code ด้านล่าง

<system.web>
<trust level="Full" originUrl=""/>
</system.web>

เป็นอันเสร็จเรียบร้อยครับ

ที่มา :
http://www.narisa.com/forums/index.php?showtopic=27585
http://www.greatfriends.biz/webboards/msg.asp?id=106519

เปิดไฟล์ Master Pages ของ ASP.NET ใน Dreamweaver 8 ให้สามารถ Design ได้

บันทึกโดย TaTump วันที่ 12 June 2010 | 195 views

โดย Master Pages ของ ASP.NET นั้นจะเป็นนามสกุล master ซึ่ง Dreamweaver จะไม่รู้จัก ถ้าเรา Open With มาก็จะเป็น Text ไม่สามารถ Design ได้ วิธีที่จะทำให้ Dreamwever รู้จักไฟล์นามสกุล master อีกหนึ่งวิธีก็คือ

  1. ให้เข้าไปที่ C:\Program Files\Macromedia\Dreamweaver 8\Configuration\DocumentTypes ถ้าเป็น Windows 64 bit ก็เปลี่ยนชื่อ Program Files ไปเป็น Program Files (x86)
  2. หาไฟล์ชื่อ MMDocumentTypes.xml เปิดด้วยโปรแกรม text editor เพื่อแก้ไขไฟล์
  3. เมื่อเปิดมาแล้วให้ค้นหา “ASP.NET_VB” และ “ASP.NET_CSharp”
  4. หา attribute ที่ชื่อว่า “winfileextension” สังเกตุจะบรรจุค่าไว้ aspx,ascx,asmx ให้เราเพิ่ม master เข้าไป ดังนั้นจะได้เป็น winfileextension=”aspx,ascx,asmx,master”
  5. ปิด Dreamweaver แล้วเปิดใหม่ครับ เสร็จเรียบร้อยครับ

“ไม่แน่ใจว่าเวอร์ชั่นอื่นจะแก้ด้วยวิธีนี้รึเปล่านะครับ แต่ผมคิดว่าพาธ config คงไม่ต่างกันมาก”

วิธีแก้ไข ASP.NET Error : The SELECT permission was denied on the object ‘table_name’, database ‘table_name’, schema ‘dbo’.

บันทึกโดย TaTump วันที่ 10 June 2010 | 136 views

จาก Error ตามหัวข้อเกิดจากไม่ได้ Add Permission (เพิ่งเคยเจอเหมือนกัน อุอุ) สามารถแก้ไขได้ดังนี้

  1. เปิดโปรแกรม SQL Server Management Studio
  2. ดูที่ Object Explorer (ด้านซ้าย)
  3. เลือกโฟลเดอร์ >> Security >> Logins
  4. เลือก User ที่ใช้งานอยู่ คลิกขวาเลือกเมนูลัด “Properties”
  5. เมื่อขึ้นหน้าต่าง ดูที่ Select a page (ด้านซ้าย)
  6. เลือก Server Role ให้ Check “sysadmin” กดปุ่ม Ok

เป็นอีกหนึ่งวิธีที่แก้ไข้ได้ครับ เรียบร้อยโรงเรียนไทย

กำหนดให้ iframe พื้นหลังโปร่งใส่

บันทึกโดย TaTump วันที่ 24 August 2009 | 866 views

ให้เพิ่ม allowtransparency=”true” ใน iframe ตามตัวอย่างด้านล่างจ้า

<iframe allowtransparency="true"  frameborder="0" src="http://example.com/iframe.php"></iframe>

แก้ไขไฟล์ hosts เพื่อเข้าเว็บโดยตรง เมื่อ DNS ยังไม่ Update

บันทึกโดย TaTump วันที่ 21 May 2009 | 744 views

 หลายครั้งที่สร้าง Domain ใหม่หรือเปลี่ยนชื่อ Domain แล้วลูกค้าไม่สามารถเข้าเว็บได้เพราะ DNS ของ internet ที่ลูกค้าใช้อยู่นั้น Update ช้า  สำหรับใครที่เจอปัญหานี้แนะนำให้ช้วิธี แก้ไขไฟล์ hosts โดยให้เข้าไปที่

C:\WINDOWS\system32\drivers\etc

จากนั้นมองหาไฟล์ที่ชื่อ hosts ให้เปิดด้วย notepad ก็ได้ครับ เมื่อเปิดมาก็ให้เพิ่ม IP Address ของเว็บ เคาะเว้นวรรคแล้วตามด้วยชื่อเว็บ จากนั้นก็ Save เป็นอันเสร็จพิธี ตัวอย่างด้านล่างเช่น เป็นการเพิ่มชื่อเว็บ www.memo8.com ชี้มา IP 61.19.251.193 จะมีหน้าตาประมาณนี้

# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

127.0.0.1       localhost

61.19.251.193 www.memo8.com

และนี่ก็คือการบอกเครื่องของเราว่าชื่อเว็บนี้ชี้ไปที่ IP นี้นะ พอเราเริ่มพิมพ์ชื่อเว็บเคาะ enter ป๊าบมันก็จะมาอ่านที่ไฟล์ host นี้ก่อนพอมันเห็น IP ที่บรรทัดเดียวกับชื่อเว็บปุ๊บมันก็วิ่งไปหา IP นั้นเลยโดยที่ไม่ต้องไปถาม DNS Server อีกแถมเร็วอีกตะหาก (ประมาณว่ารู้ทางไปแล้วโว้ย ไม่ง้อ DNS Server 555+)

ติดตั้ง IIS ไม่ได้ เพราะหาไฟล์ staxmem.dl_ ไม่เจอ

บันทึกโดย TaTump วันที่ 30 June 2008 | 768 views

ไม่ไ้ด้ติดตั้ง IIS มานานมาก พอมาติดตั้งกะไว้เขียน ASP.NET ก็เจอปัญหาตามหัวข้อ อะไรวะเนี่ย  Windows Pack2 เอากรุอีกแล้ว T_T ฮือ… เลยไปเจอวิธีแก้ไขจากเว็บ  Support ของ microsoft โดยเป็น command prompt ซ่อมแซม Database Utility ที่มีปัญหา แต่ถ้าอยากรู้ละเอียดกว่านี้ก็แปลเอาเองละกันเด้อ ผมก็มีปัญญามั่วแค่นี้แหล่ะเหอๆ แต่ได้ผล วิธีการดังนี้จ่ะ

1. คลิก Start Menu >> Run >> พิมพ์ cmd
2. ให้พิมพ์คำสั่งตามด้านล่างนี้ แล้วเคาะ Enter

esentutl /p %windir%\security\database\secedit.sdb

3. จะมีหน้าต่าง warningขึ้นมาให้กดปุ่ม OK
4. จากนั้นรอจนกว่าระบบจะ “Repair” เสร็จ

“ทีนี้ลองกลับไปติดตั้ง IIS ใหม่อีกครั้งครับ น่าจะได้แล้วล่ะ”

ที่มา : http://support.microsoft.com/kb/555268

วิธีแสดง Hidden Files ใน WS_FTP , CuteFTP และ FileZilla

บันทึกโดย TaTump วันที่ 14 June 2008 | 380 views

บางครั้งเราต้องการจัดการกับไฟล์ .htaccess หรือ .htpasswd
แต่พอupload ผ่าน FTP กับมองไม่เห็นไฟล์ดังกล่าว
เพราะServer อย่าง Linux หรือ Unix จะเซ็ตให้ไฟล์ ที่มี(.)นำหน้า เป็น system file
และ ซ่อนไฟล์นั้น และนี่ก็คือการเซ็ต FTP Client ให้แสดงไฟล์ที่ซ่อนเหล่านั้น

WS_FTP

  • Open WS_FTP
  • Click Connect
  • Select the site you wish to modify and right-click on the site
    name
  • Click Properties
  • Select the Startup tab
  • Enter -a in the Remote File Mask box
  • Click OK to confirm the changes
  • CuteFTP

  • Open CuteFTP
  • Click the Site Manager tab
  • Select the site you wish to modify
  • Select File, then Properties (when in CuteFTP Professional)
  • Select the Actions tab
  • Click the Filter button
  • Check the Enable Remote Filters check box
  • Check the Enable server side filtering check box
  • Enter -a in the Remote field
  • Click OK
  • FileZilla ( อันนี้ขอแยกเป็นเวอร์ชั่น)

    เลือกเมนู Server > Force showing hidden files สำหรับเวอร์ชั่นใหม๋ๆ
    เลือกเมนู View > View hidden files สำหรับเวอร์ชั่นเก่า

    Ref: http://www.tech-evangelist.com/category/web-site-development/

    Fix PNG Transparent on IE แบบตรงๆ

    บันทึกโดย TaTump วันที่ 23 May 2008 | 1,018 views

    จะว่าไปมี script หรือcss ที่ include แล้วใช้งานง่ายดูตามลิงค์ด้านล่าง

    http://jquery.khurshid.com/ifixpng.php

    http://koivi.com/ie-png-transparency/

    http://www.komodomedia.com/blog/2007/11/css-png-image-fix-for-ie/

    แต่บางงาน โค้ด javascript ไปตีกับ fix-png ที่เรา include มาใส่ (โอกาสน้อย ยกเว้นซวยอย่างผม T_T…)

    ก็เลยจำเป็นต้อง fix แบบรูปต่อรูปตามโค้ดด้านล่างเด้อ

    <span style="width:247;height:216px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='test.png');">
    
    <img style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="test.png" width="247" height="216" border="0" >
    
    </span>

    จากโค้ดจะมี แท็ก span ครอบ แท็ก img อีกที และมีการกำหนด Attributes ต่างๆ อาจจะยาว แต่จุดหลักที่ต้องกำหนดนั่นก็คือ

    width,height และ พาธรูป ซึ่งต้องกำหนดทั้ง แท็ก span และแท็ก img ให้ตรงกัน

    ตย. http://www.memo8.com/lab/css/png/fix-png1.html

    date_default_timezone_set(”Asia/Bangkok”);

    บันทึกโดย TaTump วันที่ 21 May 2008 | 1,291 views

    จู่ๆ โปรแกรมที่ข้าเจ้าเขียนก็มี ข้อความเตือนประมาณนี้ ลักษณะเหมือนไม่ได้ Set timezone(เวลาในพื้นที่) หรือใครไป config อะไำรสักอย่าง แต่ก่อนไม่มี เดี๋ยวนี้มีเป็นของตัวเอง “เฮ้ยยยยอารายเนี่ย….T_T”

    Strict Standards: phpinfo() [function.phpinfo]: It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Asia/Bangkok’ for ‘ICT/7.0/no DST’ instead

    เอาล่ะมาดูซิว่าเกิดอะไรขึ้น phpinfo เปิดดูหน่อย…

    date_default_timezone_set

    เมื่อรู้แล้วว่า “no value” ก็ เปิดไฟล์ php.ini แล้วหาคำว่า date.timezone และ set เป็น “Asia/Bangkok” เพราะเราคือคนไทย (หมายถึง server อยู่ที่ไทย)

    date.timezone = Asia/Bangkok

    อย่าลืม restart Apache เด้อ
    ปิ้ว…. ผมไม่มีสิทธิ์แก้ไฟล์ php.ini อ่ะ เลยมีวิธีที่สอง ก็พิมพ์คำสั่งนี้ไว้บนบรรทัดแรกของไฟล์ซะเลย

    date_default_timezone_set("Asia/Bangkok");

    เรียบร้อย…ไปดูหนังต่อดีกว่า อุอุ…

    ตรวจสอบว่าเปิดการใช้งาน Javascript อยู่หรือไม่?

    บันทึกโดย TaTump วันที่ 8 March 2008 | 3,137 views

    สืบเนื่องจากบทความ เปิด JavaScript ได้อย่างไร? นั่นสิแล้ว User จะรู้ได้ไงวะว่า กุต้องเปิด Javascript เราก็เลยต้องตั้งแจ้งเตือนไว้ที่หน้าเว็บเลย ดู script ตัวอย่าง

    html

    <noscript>
    Browser ของคุณยังไม่ได้เปิด Javascript
    </noscript>

    เอาไปดัดแปลงต่อกันเอาเองนะ ^_^

    Page 1 of 212»