Not Equal C && !=C && 不等于西
RSS icon Email icon Home icon
  • Client Side Validation For DataType Attribute in ASP.NET MVC3

    Posted on November 20th, 2012 Sean Add comments

         After Microsoft announced ADO.NET Entity Framework 4.1, database design becomes to very easy via Code First approach. And the DataType Attribute from “System.ComponentModel.DataAnnotations” namespace has been used very popular during Code First. Here are some examples:

         But be noticed, this validation of attribute only fires when you check “ModelState.IsValid” property in Controller or calling “SaveChanges()” in Entity Context, not in the client side. fortunately, JQuery has all the client side validation for those data types. So, the lazy way is just connect them together.
    Read the rest of this entry »

  • 1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
    Loading...Loading...
    640 views
  • Best way to create you own php.ini on Windows host

    Posted on June 25th, 2012 Sean Add comments

         I have a Windows host package on Godaddy.com, and recently moved my wordpress blog to this hosting server. Sometimes I need to change some php settings for the wordpress, so I decide to create my own php.ini instead of using Godaddy one.
         First of all, we don’t need to create a brand new php.ini from scratch. We can just use Godaddy’s default php.ini as reference. So, just create a php file called “phpinfo.php”, put the following code below and upload the file to your hosting server (this step is to find where the Godaddy’s php.ini file located. If you know the location, just skip this step):

         Browse this file from your hosting, and will see the phpinfo page including all the settings. Look at the line of “Loaded Configuration File” section, find the location of Godaddy’s php.ini. In my case, it’s “c:\cgi\php5\php.ini”.
         Next, create another file called “phpfile.php”, and put the following code below, then upload to the server.

         Browser this file and get a page with lot of plain text. Use your browser to view the source of this page, save the source as “php5.ini” (Note: NOT “php.ini”), and you got Godaddy’s php.ini already.
         In my case, I just need to change some settings like below:

         After modified your php5.ini, upload it to the root directory of hosting server. In Godaddy hosting, you need to do the following:

    1. Log in to your Account Manager.
    2. Click Web Hosting.
    3. Next to the hosting account you want to use, click Launch.
    4. In the Content section of the Hosting Control Center, click the IIS Management icon.
    5. Click Recycle App Pool and follow any prompts.
    6. Reload the phpinfo.php page to see if the desired changes have taken effect.
  • 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading...Loading...
    173 views
  • MVC3 with IIS7 credential error

    Posted on March 19th, 2012 Sean Add comments

         When I deploy my new MVC 3 project to a Windows 2008 R2 with IIS 7 server, I got an error with “401 – Unauthorized: Access is denied due to invalid credentials” on every page.
         After some google’s, I figure out the reason was: in my “_layout” page, I have the code “@Html.RenderAction(…)”, and the action I was trying to render actually is under “Home” controller with “[Authorize]” attribute. In another word, when IIS calling MVC pages, ASP.NET will ask for authentication, and if not authenticated, it’s supposed to redirect to “_logon” page, but unfortunately the “_logon” page (which is using “_layout” as master page of cause) also asked for authentication because of rendering action. It became to a dead end.
         Based on the reason explained above, the fastest solution is remove the “[Authorize]” attribute from the controller. But if you don’t want change your code, go to IIS management tool, select the website your are running, choose “Error Pages”, and “Edit Feature Settings”, change “Error Responses” to “Detailed errors”.

  • 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading...Loading...
    170 views
  • 搬家完成

    Posted on February 18th, 2012 Sean Add comments

         最近需要.NET环境的hosting,本想直接在1and1升级,碰巧看到costco和Godaddy合作推出hosting套餐,感觉不错,旋即决定开始实施。
         搬家的第一步是要转domain,首先要在目前的register(譬如我的情况就是1and1)把domain变成unlock,然后在新的register提申请(我的情况就是Godaddy),大概1周左右就可以完成转移的过程。然后再去以前的register取消合同就可以了。
         接下来就是搬数据库,基本上比较简单,无非就是export和import。
         最后就是搬文件和修改设置,这一步比较复杂,因为所有的数据库connection string都要重新改,所有的文件结构都有变化。不过有点耐心,慢慢来也就小菜一碟了。
         全部完成后就上来铺一帖,感觉似乎有点慢,莫非Windows的IIS真的就不如Linux好吗?

  • 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading...Loading...
    80 views
  • Custom Validation for MVC 3 Model Example 1: Positive Integer

    Posted on January 7th, 2012 Sean 2 comments

    When you define a property of the model, you can always put some MS’s attributes to validate the data, like “Required”, “Range”. Also you can use custom validation via expression or creating new attribute class. For example, the “NumberOfStock” for “Product” must be an integer and positive.
    Actually to accomplish this validation is quite easy, if use regular expression:

    The way showed above will be good enough if you only have a few models or a small application. For a big project, you might want to create your own attribute instead of using expression. The advantage of dong this is easy to centralize (if you have many custom validations), and easy to debug.
    Read the rest of this entry »

  • 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading...Loading...
    3,067 views