Ataye Development
 

The Ataye Website Blog

Monday, 14 November 2011
'AjaxControlToolkit' could not be found.

Even after adding the reference to AjaxControlToolkit the project was comaplaining that "The type or namespace name 'AjaxControlToolkit' could not be found (are you missing a using directive or an assembly reference?)".  

This project still uses uses Microsoft ASP.NET 2.0 AJAX Extensions 1.0 so i cannot use the v3.5 assembly, thus using the older toolkit library.  And it had not been installed on the new dev machine.

So how to fix?  Turns out that the toolkit relies on 2 additional assemblies, these are:

  • System.Web.Extensions.dll
  • System.Web.Extensions.Design.dll
I only had the first referenced, but after adding both assemblies did the project compile!  You can download the files in archive from here.
 
cheers
Posted by Sysadmin
Monday, 14 November 2011
IIS 7 File upload limits

So, IIS7 (and (IIS7.5) file upload limits.  We all know about it and have experienced it at one time or another.  I've just recently ran into this problem again, thinking I had it in the bag found that there were STILL problems uploading files of any decent size.  However, I found the culprit.

So there are the standard httpRuntime file upload request and disk threshold length config nodes (in KBytes):

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="40000" requestLengthDiskThreshold="40000" />
  </system.web>
</configuration>

Buit there is another little sneaky one when using IIS7 (and 7.5).  This one lives in the system.webServer config node, and is called security/requestFiltering/requestLimits 'maxAllowedContentLength'.  Just add this to your web.copnfig to increase the upload file limits (in bytes):

<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="40000000" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

Posted by Sysadmin
Wednesday, 6 April 2011
Oops, my .svn's are showing!

I use Subversion for code version control, and also use TortoiseSVN to integrate into windows explorer.  For Visual Studio i use Ankhsvn.  

i recently had an issue where a publish of a website from visual studio copied all my .svn folders into the publish folder.  I then suddenly noticed the .svn folders were showing up in Visual Studio as well.  

After looking at the source project folder i realised all my .svn folders had become unhidden.  So all i had to do was to set all the folders to hidden to stop VS from publishing them to the publish folder.  heres what i did:

FAIL

attrib +H *.svn /s

Should have worked, but because of *.svn it's looking for files and ignoring folders, grr.

SUCCESS

In windows explorer:

  1. Select the root project folder and enter .svn into the searhc box (this shows all svn folders),
  2. Ctrl-A to select all the folders, then right click and go Properties,
  3. Check Hidden.

Now they are all gone (I usually tell windows explorer to show hiden files).

cheers

Posted by Sysadmin
Tuesday, 1 February 2011
Fix Exchange 2007 OWA

Had a problem with Exchange recently which required me to fix the security settings for all the IIS virtual directories for Exchange 2007 web access.  To fix i had to remove and then re-install the Client Access Server role.  The following article outlines how to do this not just with 2007 but also with 2000 and 2003:

http://support.microsoft.com/kb/320202

To summarise, open command prompt and enter the following commands (One at a time):

  • exsetup.exe /mode:uninstall /roles:ca
  • exsetup.exe /mode:install /roles:ca

Cheers,
James

Posted by Sysadmin
Monday, 31 January 2011
Flash Actionscript AS3 Tween Brightness

Onto Flash now.  After a lot of searching and dead ends (And flash CS3 docs giving code for AS2!) i finally figured out an easy way to tween brightness of an object.  As this uses the Colour (Color) matrix transformations this also applied to colour tweening.

The Method: 

Perform a tween on a new object, and set it to tween an arbitrary property.  Set the easing and brightnes values (between 0 for dark and 255 for light), and timings as needed.  Then add a listener for TweenEvent.MOTION_CHANGE.  Within this event we build a brightness colour matrix using the current tween position and apply to the mc.filters array!

The Code:

import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.filters.ColorMatrixFilter;

var tw:Tween = new Tween(new Object(),"x",None.easeNone,200,0,5,true);
tw.addEventListener(TweenEvent.MOTION_CHANGE,function(e:TweenEvent):void
{
    var val:Number = e.position;
    var brightness_array:Array = [1, 0, 0, 0, val,
            0, 1, 0, 0, val,
            0, 0, 1, 0, val,
            0, 0, 0, 1, 0];
    mc.filters = [new ColorMatrixFilter(brightness_array)];
 });

I hope this helps someone out there!

Cheers,
James

Posted by Sysadmin
Friday, 31 December 2010
HttpListener using SSL

I have been trying for a while to get the HttpListener to work with SSL (vs2005 on XP SP2) and finally i got a break through.  All info i've found so far points to making a certificate and using httpcfg to bind the certificate to the given prefix endpoint.  I followed instructions but still it would not work (see link below, this was most helpful):

http://answers.google.com/answers/threadview?id=735306

(btw, dont change 0.0.0.0: to your ip address, leave it as is ;)

So after looking into the MSDN docs some more and playing with the httpcfg tool i found i needed to not only bind the certificate to the endpoint but also to the application.  You do this by passing the applications GUID to the set ssl command!!

Following are some commands i used to figure things out a bit:

httpcfg query ssl <-- get a list of bound certificates

and found the guid empty.  So i deleted any bound certificates:

httpcfg delete ssl -i 0.0.0.0:90

Then re issued the httpcfg set ssl command and specified the GUID from my vs2005 projects AssemblyInfo.cs, under [assembly: Guid("xxx")] as in:

httpcfg set ssl -i 0.0.0.0:8585 -c "MY" 
-g {E27BC593-0E2b-4043-AA07-1DBAFD724990}   <-- App GUID
-h 99F065C41348FBFB261E959C1A76892E91176999 <-- Cert footprint

Then i reran my app and it worked (it complained about an invalid certificate, but it is a test certificate)!!


Now this is a bit interesting:  I moved my certificate from LOCAL_MACHINE\Trusted Root Certification Authorities\Certificates into LOCAL_MACHINE\Personal\Certificates before i used httpcfg.  This seems contrairy to previous advice of leaving it in Trusted Root store but i guess this is because im running on my dev machine, not prod server!!

I hope this sheds some light on using HttpListener with SSL.

cheers
James

Posted by Sysadmin
Tuesday, 28 December 2010
Using Clientside Validator

Hello,

To use the client side validator you first need to add one to your page.  Then in html view add a new javascript method as follows: (Im using the dotnet v2.0) 

<script type="text/javascript">
function
 ValidateClientItem(sender, args)
{
    var
 sMyVal = args.Value;

    if (sMyVal != sValidString
)
    {
        args.IsValid = false
;
        return
;
    }
    args.IsValid = true
;
}
</script>

Then, set the ClientValidationFunction property of the custom validator to the name of the function, in this case 'ValidateClientItem'.  You dont need to set ControlToValidate if you dont want, but you wont be able to use args.Value.

Thats all there is to it.  When the client form is submitted, the validator is called and will in turn call your client side javascript method.  Setting args.IsValid to false cancels the form submit and displays the validator error message.

Happy coding,

James

Posted by Sysadmin
Wednesday, 15 December 2010
ASP.Net secure (or unsecure) parts of a site using web.config

Hello,

To secure my dotnet sites i like to use the built-in authorization module of dotnet using the login control.  I usually set the main web.config to allow="*" and deny="?" and by setting the authentication mode="Forms" and supplying a loginUrl="~/Login.aspx" (or some other login page) sends the user to the login page if they havn't already logged in, thus requiring authentication before access the site.

The problem with this is having the web.config sitting in the root of the site and denying all unauthorized users.  This now secures *everything* including stylesheets and images etc.  To get around this you can specify security exclusions in the web.config file using the location node.

Heres a sample:

 

<configuration>
  <system.web>
    <authentication mode="Forms"
>
      <
forms name="SiteLogin" loginUrl="~/Login.aspx"
/>
    </
authentication
>
    <
authorization
>
      <
deny users="?"
/>
      <
allow users="*"
/>
    </
authorization
>
  </system.web>

 

  <location path="SiteStyle.css">
    <
system.web
>
      <
authorization
>
        <
allow users="?"
 />
      </
authorization
>
    </
system.web
>
  </
location>

  <location path="images">
    <
system.web
>
      <
authorization
>
        <
allow users="?"
 />
      </
authorization
>
    </
system.web
>
  </
location>
<configuration>

The above is the web.config which sits in the root of the site.  The two location nodes specifies that anonymous users can access the SiteStyle.css file and all files within the images folder!

Cheers,

James

Posted by Sysadmin
Thursday, 7 October 2010
Microsoft Devsta 2008 submission - Ataye Ascii Image Viewer - 5th Place!!

UPDATE: Well i came in at 5th place, and wn $2000 worth of prizes, i'm pretty chuffed :D

Its been a while since i've updated this blog so I am finally updating with my entry in the Microsoft Devsta 2008 competition.

In keeping with the old school demo and graphics scene, i have created an ascii image viewer.  It takes you back to the old image rendering method of using text to display graphics.

It is also complete with an ascii based intro / demo.

Whats different about this??  It take an 'old school' methodology and re-creates it using new cool technologies like GDI+ with Visual Studio 2008.

Lets see how it goes :O)

Posted by Sysadmin
Saturday, 2 October 2010
How to return identity after doing an Insert with ADODB and Classic ASP

Hello,

Today i thought i'd share an easy way to return an identity after doing an insert with classic ASP and the ADODB object.

Basically we open a connection and perform actions on the open connection, then close when we are finished.  By keeping the connection open we are re-using the same session.  Following is a code listing.

Dim cnn, rsPK, sSql, iTablePK

' Open a connection:
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.Open ConnString

' Perform the insert into our table:
sSql = "INSERT INTO tbOrderDetails (FKOrderID, TourCode) values (1, 'Code')"
cnn.Execute sSql, , adCmdText + adExecuteNoRecords

' Retrieve the identity:
set rsPK = Server.CreateObject("ADODB.Recordset")
rsPK.Open "SELECT @@Identity", cnn,  0, 1, 1

' We now have the new record PK in iTablePK!
if (not rsPK.EOF) then
   iTablePK = rsPK(0)
end if

' Clean up:
cnn.close
set cnn = nothing

So, we open a connection and while we keep it open we perform the insert into the table with the identity field.  We then select the new table field using @@identity.  Keep in mind @@identity is GLOBAL to the connection, meaning it will return the latest identity regardless of where the insert occured!!  (i.e. table trigger performing an insert).  To be safer you could use the SCOPE_IDENTITY() method, which is LOCAL to the table.

Ok, i hope this helps.

Cheers,
James

Posted by Sysadmin
Friday, 1 October 2010
Return identity with DotNET SQL Datasource

Here is a little trick i use to return the identity from a PK column after doing an insert with the Sql Data source component.  Since this is done at the data source level it can be used with any databound control like the FormView, DetailsView or any other 2-way databound control.

To make this happen just do the following:

  1. Enter your insert command and setup your datasource for inserting.
  2. Append to the end of the insert (this can be done in the Source view of the page) the following:
    • ; select @PK=SCOPE_IDENTITY();
  3. Now add a new parameter to the <InsertParameters> node of the SqlDataSource (Change the datatype to match):
    • <asp:Parameter Name="PK" Direction="Output" Type="Int16" />
  4. No you can access the new PK value in the 'Inserted' event after the data has been inserted eg:
    • this.Response.Write(e.Command.Parameters["@PK"].Value.ToString());

So what happenes is after the insert the sql sets the new identity to the parameter @PK which is declared on the data source as an output parameter.  Then the value can be read after the insert through the Inserted event.

I hope this helps.

Happy coding.

Posted by Sysadmin
 


Copyright 2011 Ataye web development