rss feed blog search engine
 
Search rss blog search engine
 
ASP.NET Cafe  
Released:  12/17/2007 4:58:19 AM
RSS Link:  http://feeds.feedburner.com/AspnetCafe
Last View 8/29/2008 7:50:51 PM
Last Refresh 8/29/2008 7:50:55 PM
Page Views 1277
Comments:  Read user comments (0)
Save It Add to Technorati Add to Del.icio.us Add to Furl Add to Yahoo My Web 2.0 Add to My MSN Add to Google Add to My Yahoo! ASP.NET Cafe



Description:



Tips and Tricks


Contents:

23 august FFMPEG Win32 build (updated)

 

If you don't know what is FFMPEG... you possible don't need this.

Or can check out http://ffmpeg.mplayerhq.hu/ 

But really, originally written for Linux it's hard to find fresh Windows binaries.  It's possible to build it, using MinGW and MSys.

I'm posting my 23 august build:

 build_08_23_08.zip (4,14 mb)

But it was sad build, it still does not encode to h264 (mp4). If someone knows how to build it with such support, please let me know. 

Added: 

Build with libx264 and even makes h264 videos ( some troubles with bitrate, but I think minor ) 

ffmpeg_13981.zip (6,26 mb)




ASP.NET 2.0 Big files upload on IIS 6.0 under Win2003

Recently faced the big problem with big files. Not so big, just needed to post files with size about 10-20MB to aspx page. With usage of quite standard control on the page.

Everybody know ( if not - I notice here ) that in web.config you have HttpRuntime settings. And one of these settings is  maxRequestLength .In theor, after adding of this line to web.config file everything should work fine.

 <httpRuntime maxRequestLength="100000"/>

But in fact you can face the problem of limit in IIS. And this is a pain in the ass. Because you need to edit Metabase.xml on server. Sometimes this can be impossible, but sometimes you can do this yourself or ask support. Here is some insturctions to make big files uploads work for you.

IIS 6 has a limit on the maximum number of bytes that can be contained in an ASP request.  By default, that limit is 4 MB. To change this:

  1. Open IIS (Start->Programs->Administrative Tools-Internet Information Services)
  2. Right-Click the server name and select Properties
  3. Check the Enable Direct Metabase Edit box and hit Apply
  4. Next browse to and open the Metabase.xml file. It is typically located in c:WindowsSystem32inetsrv directory.  You can use Notepad to modify this file.
  5. Search for "ASPMaxRequestEntityAllowed" and change its value to "1073741824"
  6. Save changes in Notepad and exit.
Later you can set your own limits in web.config. For example, using <location> tag you can apply maxRequestLength only for specific pages.




Better call for NotifyScriptLoaded in AJAX
Already on Bora bora ? I'm not...

Recently found one thing. Perhaps in docs for AJAX client or somewhere else was such line:

Sys.Application.notifyScriptLoaded(); 

You need to write this line at the end of your JS files. But this can cause the problems if you wish to re-use this code in non-ajax enviroment. For this better to use following line:

if (typeof(Sys) !== 'undefined')  Sys.Application.notifyScriptLoaded(); 

This makes things a bit better. Also, it answers another question - "Testing for defined variables in Javascript".  Sometimes I see the code like:

if( Sys )...  // And this will fail in case Sys is undefined. 

 That's all for now, it's summer. Everybody enjoy their resort life. But I'm still working.

 




ForceWrap or when you need a whitespace

Sometimes on websites with user content you can find some design issues because of their content. Actually, I'm about the stuff like

"Swimming*Skimboaring*AquaFitness*Snorkeling*Kayaking*Basketball*Archery*Volleyball*Soccer*Table Tennis*Mini Golf*Badminton*Rock Climbing* Kiteboarding*Fencing*Gymnastics*Yoga*Pilates*"

But we ( as developers want to get rid of such ugly stuff that moves across the bounds of area and can't be wrapped - because there are no white-space inside.

For this I just written force wrap function. It is quite simple, using regular expressions

 protected static string ForceWrap(string aStr,int max)
        {
            Regex LongLine = new Regex(@"(?<long>S{"+max.ToString()+",})");
            MatchCollection matches = LongLine.Matches(aStr); // find all matches of "Long Strings" //
            if (matches.Count > 0)
            {
                StringBuilder sb = new StringBuilder(aStr);
                
                for (int i = 0; i < matches.Count; i++)
                {
                    string s = matches[i].Groups["long"].Value;
                    string origS = s;
                    int segments = s.Length / max;
                    for (int j = 1; j < (segments+1); j++)
                    {
                        int pos = j * max + (j-1);
                        s = s.Insert( pos , " "); // Insert Space //
                    }
                    sb.Replace(origS, s);
                }
                aStr = sb.ToString();
            }
            return aStr;
        }
 

 

First parameter - the string you want to output, the second - max lenght is chars. Return value is new string with whitespace inserted if needed.

I think this is useful, but if there are something better, please let me know. 

 




Google maps for Flash (Flex) API

Good news from Google Maps team again. Recently I've found api for Flex. This is a great advantage for actionscript developers. First of all, I've already mentioned that JS api is a bit slow thing... And specially I though about Flex/Flash maps API ( like Yahoo maps provided before ). And right now we have it.

At the first look not so "super" like JS api. But this is a big hit, I think.

 

Preformance of Flash API is great - very smooth moving, great animations. But you can see that graphics is not so awesome, info window looks "poor" and marker not so good like in JS version. But I think that Flash engine much better fits mapping tasks, first of all because of performance, it does not affect other stuff on your page, running inside flash player, optimized for animation and that's why very-very fast. API is done for Flex ( Flex SDK is free stuff that you can run from Eclipse ). Frankly, I think this is a good news , but I'll wait a bit... First of all I don't think that everybody updated Flash player to version 9 ( exactly this version needed to run Flex application ).

Anyway - this is a great news for everybody who is working with maps.

http://code.google.com/apis/maps/documentation/flash/intro.html

 




Google maps: Static maps

Google maps one of the best mapping API. But sometimes you don't need navigation, zoom and other cool stuff. Sometimes you need something simple. Simple and fast. Yes, google maps makes a page a bit slowly, a bit big, just because this is maps. Looks like guys from Google understood this. Sometimes you don't want to load all the tiles and JS API. You just need to show some address or route on the map. And here static maps can help you. Static map can show simple markers and even routes.

What is so special with these static maps? Static maps is just an url, nothing more, no JS. This is URL that points to the image.

http://maps.google.com/staticmap?center=40.714728,-73.998672&
zoom=14&size=512x512&maptype=mobile&
markers=40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc&
key=ABQIAAAAb1NmS6C8S9-MMXlYL9Q-RRSx6c7sV4hKqe-jPp9AwgHIMiXszhRaLoR4qw61u_5jZn9ohtUjCjYruw

And looks like Sample Static Map

Looks impressive. I found this very useful in my projects. Maybe you find too.

All data comes in URL. And this makes things a bit limited. But in case if you want to show just address of the company/shop on the map - useful. You can even show some routes from one location to another location. And nobody limit you in your fantasy. You can write back-end in ASP.NET which can easily show any place on the map. And the last advantage - it's very simple to understood and start using - 5 minutes at all.

More about Static Maps at : http://code.google.com/apis/maps/documentation/staticmaps/

Static maps Wizard at: http://gmaps-samples.googlecode.com/svn/trunk/simplewizard/makestaticmap.html

Special thanks to Google Maps team. 




Credit Card number validation in C#. Visa and MC.

Credit card numbers are full of magic. First of all not every 16 digit is CC number, but only by number you can know the issuer. So no need to place on the web form "Visa" / "MasterCard" radio button. Ok, so what's interesting. I found two great articles that helped me with this:
http://www.merriampark.com/anatomycc.htm and http://www.beachnet.com/~hstiles/cardtype.html .

And what now ? I just finished small helper class to validate Credit Cards. Here is the source.

public enum CCType 
    {
        VISA, MC
    } 


    /// <summary>
    /// Credit card validation.
    /// Supports : VISA and MasterCard
    /// Reference: http://www.merriampark.com/anatomycc.htm
    /// Contains LUHN (mod 10) check
    /// by D.S.
    /// http://aspnetcafe.com
    /// </summary>
    public class CreditCardValidator
    {
        protected string _CardNumber = ""; 


        public CreditCardValidator(string aCardNumber)
        {
            _CardNumber = aCardNumber.Replace(" ","").Replace("-","");
            ProcessValidation();
        } 


        protected bool _IsValid; 


        public bool IsValid
        {
            get { return _IsValid; }
            set { _IsValid = value; }
        } 


        private CCType _CardType; 


        public CCType CardType
        {
            get { return _CardType; }
            set { _CardType = value; }
        }
        
        protected void ProcessValidation()
        {
            bool passRegEx = false;
            bool passIssuer = false;
            bool passLuhn = false;
            IsValid = false; 


            do
            {
                // Reg Ex check //
                Regex RegExNumber = new Regex(@"(?<firsttwo>(?<firstone>d)d)d{11,14}");
                Match m = RegExNumber.Match(_CardNumber);
                passRegEx = m.Success;
                if (!passRegEx) break;
                string number = m.Groups[0].Value; // only digits //
                string firstNum = m.Groups["firstone"].Value;
                int firstTwoNum = int.Parse(  m.Groups["firsttwo"].Value );
                passIssuer = (firstNum == "4") || ((firstTwoNum >= 51) && (firstTwoNum <= 55));
                if (!passIssuer) break;
                if (firstNum == "4") CardType = CCType.VISA;
                if ((firstTwoNum >= 51) && (firstTwoNum <= 55)) CardType = CCType.MC;
                // Now make Luhn check //
                passLuhn = LuhnCheck(number);
                if (!passLuhn) break;
                //
                IsValid = true;
            } while (false);           
        } 


        /// <summary>
        /// Performs mod 10 check
        /// </summary>
        /// <param name="cardNumber">Card Number with only numbers</param>
        /// <returns></returns>
        protected bool LuhnCheck(String cardNumber)
        {
            int sum = 0;
            


					
				

Home  
 


Link to us




RSS Feed of new blogs                                                   Home        Feed Map        Submit Feed      Link to Us       Contact