วันพุธที่ 4 ธันวาคม พ.ศ. 2556

Allow C# to manager IIS when use Microsoft.Web.Administration

I use reference Microsoft.Web.Administration from
C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll

to read IIs Status must allow IIS user readable on folder
C:\Windows\System32\inetsrv\config

and to write or change IIS must writable on it.

It can create new user and set to Application pool and allow this user for read and write on above folder.

วันจันทร์ที่ 4 พฤศจิกายน พ.ศ. 2556

IIS Express stop process when stop debug in Visual Studio 2013

This is feature in new Visual Studio call "Enable Edit and Continue"
If don't want to close IIS Express go to Project Properties > Web >
to unchecked "Enable Edit and Continue" to let IIS express continue after stop debug.

this setting is default on when create new Project.

วันศุกร์ที่ 1 พฤศจิกายน พ.ศ. 2556

System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to

[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Users\xxxx\AppData\Local\Temp\Temporary ASP.NET Files\root\fe4980a2\10ea1996\assembly\dl3\33a3ac9e\f6af08a0_f8d6ce01\System.Web.WebPages.Razor.dll'.
This happen today when I use Nuget upgrade my MVC 4 asp.net 4.5 to last version on 1 November 2013 but can't get my project run normally after upgrade.
Normally look like I got System.Web.Razor version 3.0.0.0 but my web still use version 2.0.0.0 so I try to fix this
first change in root web.config by this
from
    <appSettings>
        <add key="webpages:Version" value="2.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="PreserveLoginUrl" value="true" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    </appSettings>
to
    <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="PreserveLoginUrl" value="true" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    </appSettings>
from
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
            </dependentAssembly>
to
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
            </dependentAssembly>

change in web.config in ~/Views/
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
    </configSections>
to
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
    </configSections>

from
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
to
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

from
        <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <controls>
                <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
            </controls>
        </pages>
to
        <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <controls>
                <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
            </controls>
        </pages>

now I can run my project with no problem (for now...)
Update...
yes i can build and run but intellisense not work anymore  look like i need Visual Studio 2003 for this job done.

วันพุธที่ 9 ตุลาคม พ.ศ. 2556

This backend version is not supported to design database diagrams or tables. (MS Visual Database Tools)

From previous I try to change table field size in SQL Server Management Studio I got this message appear and can't change anything with my table so I realize I use Server Management 2008R2 but my Database version is 2012 for now so I change Server Management to use version 2012 and it work fine. to avoid this don't use old version to edit new version that's all.

Increase Mantis bug tracker summary field length.

Mantis bug tracker is good but with limit summary filed is not good for me. I need to expand from 128 character to 255 for can fill in more summary for me.

we have 3 place to change.
1. in Database open and go to "mantis_bug_table" in field "summary" expand from varchar(128) to varchar(255)
2. in  source page "bug_report_page.php" and "bug_update_advanced_page.php" go to
line contain
type="text" name="summary" size="105" maxlength="128"
and change it to
type="text" name="summary" size="105" maxlength="255"
u have to change this line in both files.

all done can test and enjoy with more summary field
hint : Current version i used is 1.2.15 and with Ms SQL 2012
then
"bug_report_page.php" change in line 475
and
"bug_update_advanced_page.php" change in line 577

วันอังคารที่ 20 สิงหาคม พ.ศ. 2556

Format number % in High Chart

I try pie chart but it have 2 categories and show 33.33333333333333 % and 66.66666666666666 %
then i try to format this number

in code have 2 part for show this number first is tooltip that will show when mouse over
and label for static show look at

this.percentage

and change it to this

this.percentage.toFixed(2)


hope this help

วันพุธที่ 31 กรกฎาคม พ.ศ. 2556

Oracle XE Connect in command line.

user command

sqlplus / as sysdba

enter for connect as sysdba

วันจันทร์ที่ 29 กรกฎาคม พ.ศ. 2556

Disable SimpleMembership in MVC 4

Today I need to use simple membership in web.config but SimpleMembership in MVC 4 is not simple.

First u need to custom Web.config like this
        <authentication mode="Forms">
            <forms loginUrl="~/Account/Login" timeout="2880" >
                <credentials passwordFormat="Clear">
                    <user name="test" password="test"/>
                </credentials>
            </forms>
        </authentication>

add this to AppSettings
<add key="enableSimpleMembership" value="false"/>

and in AccountController disable InitializeSimpleMembership
//[InitializeSimpleMembership]

now for Login use this for realy simple life.

        // POST: /Account/Login

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult Login( LoginModel model, string returnUrl )
        {
            //if (ModelState.IsValid && WebSecurity.Login( model.UserName, model.Password, persistCookie: model.RememberMe ))
            //{
            //    return RedirectToLocal( returnUrl );
            //}
            if (!ValidateLogOn( model.UserName, model.Password ))
                return View( model );

            FormsAuthentication.SetAuthCookie( model.UserName, model.RememberMe );

            if (!String.IsNullOrEmpty( returnUrl ))
                return Redirect( returnUrl );
            else
                return RedirectToAction( "LogOn" );

            //// If we got this far, something failed, redisplay form
            //ModelState.AddModelError( "", "The user name or password provided is incorrect." );
            //return View( model );
        }

        //Add Custom Validate for validate user and pass in Web.config
        private bool ValidateLogOn( string userName, string passWord )
        {
            if (string.IsNullOrEmpty( userName ))
                ModelState.AddModelError( "username", "User name required" );

            if (string.IsNullOrEmpty( passWord ))
                ModelState.AddModelError( "password", "Password required" );

            if (ModelState.IsValid && !FormsAuthentication.Authenticate( userName, passWord ))
                ModelState.AddModelError( "_FORM", "Wrong user name or password" );

            return ModelState.IsValid;
        }
        //End Custom Validate

        //
        // POST: /Account/LogOff

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult LogOff()
        {
            //WebSecurity.Logout();

            //return RedirectToAction( "Index", "Home" );

            FormsAuthentication.SignOut();
            return RedirectToAction( "LogOn" );
        }

c# Assembly QualifiedName format and How to find.

Format is
NamespaceQualifiedTypeName, AssemblyName
 
How to get is
 
Type objType = typeof(System.Array);

        // Print the full assembly name.
        Console.WriteLine ("Full assembly name:\n   {0}.", 
                           objType.Assembly.FullName.ToString()); 

        // Print the qualified assembly name.
        Console.WriteLine ("Qualified assembly name:\n   {0}.", 
                           objType.AssemblyQualifiedName.ToString());  

วันจันทร์ที่ 1 กรกฎาคม พ.ศ. 2556

Integrate NLog in my MVC 4

use Nuget to get NLog to your MVC
current version is 2.0.1.2 ad 1/7/2555 (d/m/yyyy)

create file NLog.config and input this

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <variable name="appName" value="MOTEWorkflow" />
    <targets>
        <target name="console" xsi:type="ColoredConsole"
          layout="${date:format=HH\:mm\:ss}|${level}|${stacktrace}|${message}" />
        <target name="file" xsi:type="File" fileName="${basedir}/Logs/rrLog.log"
          layout="${date}: ${message}" />
    </targets>
    <rules>
        <logger name="*" minlevel="Info" writeTo="file" />
    </rules>
</nlog>

then when need log use like this

NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
logger.Error( "Test Error" );

this is simple but more configuration and details can be found here.
https://github.com/NLog/NLog/wiki

วันเสาร์ที่ 29 มิถุนายน พ.ศ. 2556

Create Private VPN with OpenVPN and Windows AZure (Ubuntu) or AWS EC 2 (Ubuntu)

(This Begin part for Azure or AWS EC2 is same the different is between connect with putty)
Azure use Username and password.
AWS EC2 need private key to connected.

After first part start your server is same on both 

Check version Ubuntu for 32 bit or 64 bit
uname -a

Download OpenVPN (Depend on your system is 32 or 64 bit u can check last software version at openvpn.org)
wget -c http://swupdate.openvpn.org/as/openvpn-as-1.8.5-Ubuntu12.amd_64.deb

Install OpenVPN
sudo dpkg -i openvpn-as-1.8.5-Ubuntu12.amd_64.deb

Change openvpn password for safety
sudo passwd openvpn


Command Add User
sudo adduser [username]

Command Update & Upgrade Ubuntu
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

วันพฤหัสบดีที่ 27 มิถุนายน พ.ศ. 2556

Install YAF (Yet Another .NET Forum) in subfolder of MVC

You will got error from the start but with this step will make you pass.
1. add <remove namespace="..."/> in yaf  web.config line 72 for not conflict with MVC
            <namespaces>
                <remove namespace="System.Web.Mvc.Html"/>
                <remove namespace="System.Web.Mvc"/>
                <remove namespace="System.Web.Optimization"/>
                <remove namespace="System.Web.Mvc.Ajax"/>
                <remove namespace="System.Web.Helpers"/>
                <add namespace="YAF.Core"/>
                <add namespace="YAF.Controls"/>
                <add namespace="YAF.Utils"/>
                <add namespace="YAF.Types.Interfaces"/>
                <add namespace="YAF.Types"/>
            </namespaces>
2. Go to folder u can install normally now.

วันจันทร์ที่ 10 มิถุนายน พ.ศ. 2556

EPPlus Format cell as text.

I need to type like 08x-xxx-xxxx but can't because General format will convert text to number and will be 8x-xxx-xxxx that not fit requirement.

fix this by
worksheet.Cells["A1"].Style.NumberFormat.Format="@"

this command will convert cell to Text Style.

วันพุธที่ 5 มิถุนายน พ.ศ. 2556

Method not found: 'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMethodException: Method not found: 'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'.



[InvalidOperationException: The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588]
   Mot_Inspector_Report.Filters.SimpleMembershipInitializer..ctor() +260
 
This error can happen when u try to publish .NET MVC (asp.net 4.00)
because u use Entity Framework 5 with .NET 4.0 instead of 4.5   

simple to fix this is uninstall Entity Framework 5 and re Install it.

use library package manager to do this

and after that may be u found this because u update plugin with "library package manager"

The "EnsureBindingRedirects" task failed unexpectedly.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Roxel.BuildTasks.EnsureBindingRedirects.MergeBindingRedirectsFromElements(IEnumerable`1 dependentAssemblies)
   at Roxel.BuildTasks.EnsureBindingRedirects.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()    Mot_Inspector_Report
 

วันพฤหัสบดีที่ 23 พฤษภาคม พ.ศ. 2556

C# Ajax.ActionLink How to Add Onclick for confirm or validate.

I try to insert onclick or @onclick in html attribute but it don't work.
so I try research and found this

@Ajax.ActionLink("Done", "ActionName", 
    new AjaxOptions 
    { 
        OnBegin = "return ConfirmDone()", 
        UpdateTargetId = "MyContainerId" 
    })
@Ajax.ActionLink("Done", "ActionName", 
    new AjaxOptions 
    { 
        Confirm= "Are you sure you want to do this?", 
        UpdateTargetId = "MyContainerId" 
    })
With this i can add function validate on begin or add confirm before click from Ajax Option.

ref: http://stackoverflow.com/questions/9604942/asp-net-mvc3-ajax-actionlink-conditional-confirmation-dialog-box

วันอังคารที่ 14 พฤษภาคม พ.ศ. 2556

DB2 7.2 There is no available conversion for the Source Code page

The Connection test failed.
[IBM][CLI Driver]SQL0332N There is no available conversion for the Source Code page "1254" to the target code page "874". Reason Code "1".
SQLSTATATE =57017
This error mean your language in client and server does not match.
Change your language by change system locale to match server and restart.

วันจันทร์ที่ 13 พฤษภาคม พ.ศ. 2556

Oracle : Import Export Whole DB

Export
set NLS_LANG=English
exp userid=[oldusername]/[oldpassword]@[sid] grants=no file=[filename].dmp
Import
set NLS_LANG=English
imp [username]/[password] file=[filename].dmp  full=yes

*may u need to grant extra role for import
SQL> grant imp_full_database to [username];

Oracle : Create new user

1. Check all users.
Start SQLPlus
If u are administrator
type
sqlpus / as sysdba
for login as sysdba
your password is sys password
type
select * from all_users;
for check all users.

2. Create new Table Space for new user (Or use old one.)
create tablespace TableSapceName datafile '[path]'
size 32m autoextend on
next 32m maxsize 2048m extent management local;
your default path for Oracle 11g Express is
'c:\oraclexe\app\oracle\oradata\XE\TableSpaceName.dbf'
dbf file will create automatically

3. Create new user with default table space.
CREATE USER [Name] IDENTIFIED BY [pass]
DEFAULT TABLESPACE "TableSpaceName"
TEMPORARY TABLESPACE "TEMP";

4. Alter user to unlimited with this tablespace.
ALTER USER [username] QUOTA UNLIMITED ON [TablespaceName];
5. Grant user permission
GRANT create procedure, create session, create table,
create type, create view, create synonym, create trigger,
resource TO [username];

grant imp_full_database to [username];

วันพุธที่ 17 เมษายน พ.ศ. 2556

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

Install this patch from this

http://www.microsoft.com/en-us/download/details.aspx?id=13255

only 32bit version can use.

and you must config Buid : Platform target to "x86"

after install restart for make it work.

GG.