Technolog

Blogging over technologie.
Welcome to Technolog Sign in | Join | Help
in Search

eprogrammer

Browse by Tags

  • SiteMaps made easy

      If you’re a site admin or asp.net developer for an internet site, you certainly need to look into sitemaps, if you want to perform SEO. It’s not necessary to  simply crawl your own site and then to give every page a priority, but consider Read More...
  • Howto: Create a custom numeric pager for the ASP.NET Gridview Control

    Figure 1: Our custom pager in action! I never have liked the concept of storing all the data in whatever form (DataTable/Lists of records/etc.) to the ASP.NET gridview control and having it automatically manage paging for me. This could however be improved Read More...
  • Howto: Check the case sensitive existence of a file

    Sometimes, especially for files running on external FTP servers, where file names are case sensitive, a file named myFILE.html, is not the same file as myfile.html in the same path! This function, can be used on an NTFS path for that purpose where File.Exists Read More...
  • Howto: Properly use the AccessCheck API for the current user

    I've seen people pulling the hair out for not getting this API workign for them. The API, even if impersonating the current user, returns error 1309. "An attempt has been made to operate on an impersonation token by a thread that is not currently Read More...
  • Fill a dropdownlist using the current UICulture in (ASP.NET)

    Just for educational purpose (as for myself as well :) ) I post this code. Using this, a programmer can use a good practise, that is to use the culture information which is built in, into .NET instead of making that data him/herself. based upon the following Read More...
  • Performance and the future of LINQ expressions

    I was wondering if writing well known C# (or VB.NET if you wish) code flow statements, such as for .. and foreach etc. are faster or slower compared to a generic expression. The results are refreshing . At least using this simple array iteration. Array Read More...
  • Howto program a LINQ expression which effectively does an aggregate subquery with optional cardinal relationship

    LINQ! Yes, Also I fell in love with linq. So here is my first try. And as you fans know, I like to dig into subjects. Maybe, the title is a little incorrect, but I wanted a query that returns one record, using a subquery in one statement! Using SQL syntax, Read More...
  • Howto loop through each element on a SafeArray with an unknown number of Dimensions?

    I thought that the subject ‘SafeArrays’ were really from the previous age and there was really nothing new about them, I could tell you , that was not already known. So sit back and listen, what I am going to tell you, has been decided, in Read More...
  • HttpWebRequest on DotNet 2.0 driving you crazy for a B2B request? Disable ServicePointManager.Expect100Continue first!

    Imagine, you have written a succesfull gateway to say, the European Community to check the validity of a VAT number. It always works, but suddenly it does not work anymore. What's up? Could it be that some service pack modified the behaviour of the Read More...
  • ATL: Tiny but good Improvements on Visual Studio Sevice Pack 1 for ATL.

    I'm glad to see, that MS still did not get rid of ATL and continued to support us, that's those guys, who think that .NET is really awful, but not the holy grail :) If you want to see it yourselfs, get a copy of windiff.exe or just run it, and Read More...
  • HOWTO: Associate a custom WKGUID (well known guid) to a custom Container

    Active Directory and ADSI (ldap in fact) have many unutilized features that, if the APIs would explain better be used much better! Let me draw a situation for you. Imagine you have an app, that is distributed and sold among international customers (congrats Read More...
  • [ATL, CPP] How to log to a machine global logfile from different threads and processes.

    Each self-respecting programmer and software team uses logging features. In my current job on ASP.NET, each click, every navigation and message is logged. Very handy indeed because you would like to support your customers. For a classic C++ project this Read More...
  • Kerberos Negotiate authentication on IIS sucks

    I just had to say  it! Yes, I was frustrated.

    Negotiate (through kerberos) on IIS sucks!
    I love free speech, especially if something said is simply true (Joe Kaplan agreed with me)! Of course, this is not an excuse to be rude to MS employees :), but they never would improve things, if we don't ask for it right?

    Why is Kerberos on IIS such a pain?
    I need an Intranet site, running ASPX to utilize integrated security. That's nice. So, I don't have to maintain another user database (bleeh, not again). Secondly, for my AD solutions, I just needed full security based on AD, and (again) not my own security mechanism.
    I hear you say: "What this fuzz about? It just works? Yes, it just works -as long as the credential on the current browser-IIS session- does not need to go any further than a page. For SQL Server, most developers, still would use standard security (and not pass-through authentication, which needs kerberos).
    But for Exchange-, ADSI-, or Active Directory enabled pages, pages that -really do something- with Active Directory, IIS and Kerberos really need a professor (Joe Kaplan, but his fee is too high for me :) ) in Windows-kerberos-science.

    Well, euh, it's easy, just 3 things to check!

    there is

    1. AD (Active Directory) support (does AD trust IIS+host for delegation?)
    2. IIS - support (does IIS support Negotiate?)
    3. Browser support (do IE support Negotiate and integrated logon?)

    And between the lines, you need to make sure (such as using setspn.exe) that it all is going to work. To get this done and configured, you'd better not be a third party intranet supplier!

    Microsoft, please, fix this. I mean, make it more easy for us.

    Let me just enumerate some knowledgebase articles that give some checklists. (See knowledge base articles below, note there are much more articles about this subject!)

    For a script, yummy for you, you might not have found this script before, because I'm just good :). What it does, is checking (enabling) the IIS server delegation. Note, using it is for your own risk!
    (ps: My setup scripts are preferable VBS because that just works without any version messup).


    What it does is actually shown in the picture. It checks the middle option.
    Delegation for IIS needed for Negotiate work.

    update at 14 sep 2006: Some companies, have disabled netbios features and computer browsing. So they solely have DNS and AD, but this makes IIS fail to use negotiate as well. It just seems that IIS has a lot of legacy network component dependencies.

    ' this checks this IIS server, to be trusted

    ' otherwise, Negotiate (Wdigest) through kerberos will -not- work!

    ' if you don't like all protocols to be trusted, you should manually correct this property

    '  for this IIS server.

    Sub SetThisIISServerTrusted()

        Dim nt, ds, ldapHost, info, accInfo, dnMe

        Const ADS_NAME_INITTYPE_SERVER = 2, ADS_NAME_TYPE_NT4 = 3, _

            ADS_NAME_TYPE_1779 = 1, ADS_UF_TRUSTED_FOR_DELEGATION = &H80000   

       

        Set nt = CreateObject("NameTranslate")

        Set info = CreateObject("WinNTSystemInfo")

        Set ds = GetObject("LDAP://rootDSE")

        ' the AD server that is serving us must be authorative enough

        ldapHost = ds.Get("dnsHostName")

       

       nt.Init ADS_NAME_INITTYPE_SERVER, ldapHost

       ' computer name is by definition the netbiosname plus a $

       nt.Set ADS_NAME_TYPE_NT4, info.DomainName + "\" + info.ComputerName + "$"

      

       dnMe = nt.Get(ADS_NAME_TYPE_1779)

       Set ds = GetObject("LDAP://" + dnMe)

       accInfo = ds.Get("userAccountControl")

       accInfo = accInfo Or ADS_UF_TRUSTED_FOR_DELEGATION

       ds.Put "userAccountControl", accInfo

       On Error Resume Next

       ds.SetInfo

       If Err.Number > 0 Then

           WScript.Echo " Error at SetThisIISServerTrusted:" + Err.Description + ":" + Err.Source + ":" + Hex(Err.Number)

       End If

       On Error Goto 0

       Set ds = Nothing

    End Sub

     

    PRB: "Access Denied" Error Message When Using ServerXMLHTTP to Access an Authenticated Site
    ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.KB.v10.en/enu_kbmsxmlkb/msxmlkb/291008.htm

    Enable negotiate on IE6
    ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.KB.v10.en/enu_kbie/ie/299838.htm

    Troubleshoot IIS negiotiate 326985
    http://www.microsoft.com/technet/prodtechnol/windowsserver2003/technologies/security/tkerbdel.mspx


    Enable negotiate on IIS
    ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.KB.v10.en/enu_kbiis/iis/215383.htm

    Enable negotiate using XMLHttp
    ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.KB.v10.en/enu_kbmsxmlkb/msxmlkb/314404.htm

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

     

     

  • Boost BSTR performance for free, by 3000%

    You don't need to if you thought so :) use CString only to get the best of string manipulation within the C++ environment in a mixed COM environment. This CComBSTR replacement offers the most you need without having to cast strings forward and backward and loose performance. Expect your multithreaded and SMP performance to improve while still using native BSTR variable storage.
  • Howto: Dynamically Create Gradient Buttons using ASPX and .NET

    If you ever might want cute buttons, independently of your clients browser and theme, you might create buttons by using some dynamic GDI based code.

     

    I found this solution, which costed just 2 hours programming not bad at all, and you might profit from it as well.

     

    This code, automatically wraps text, all using .NET power. It even can be improved, to support hover as well. B.t.w. on Windows Vista XAML supports this but we’re still on the internet man!

    So why not make our own buttons.

     

    Paste code below, onto an empty ASPX page (for instance button.aspx), and call use it through the following arguments (other tag arguments omitted for simplicity).

     

    <asp:ImageButton id=”myButton” ImageUrl=Button.aspx?t=Hello%20World&w=150&h=35” runat=”server”/>

     

    Syntax below is based on C# 2.0 

     

    The output might look like this(appConfig must contain the buttoncolors)

    gradientButton

     

    public partial class button : System.Web.UI.Page

    {

        private static Color parsRgb(string rgbColor)

        {

            int red, green, blue;

     

            red = int.Parse(rgbColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);

            green = int.Parse(rgbColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);

            blue = int.Parse(rgbColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);

     

            return Color.FromArgb(red, green, blue);

        }

        protected void Page_Load(object sender, EventArgs e)

        {

            System.Collections.Specialized.NameValueCollection req= Request.QueryString;

           

            //get height

            string h=req["h"];

            //get width

            string w = req["w"];

            // get text

            string t = req["t"];

            if (t == null || t.Length == 0)

                throw new HttpException("QueryString  t not supplied");

            int hashCode = t.GetHashCode();

            string checkEtag = Request.Headers["ETag"];

            if (checkEtag != null && checkEtag.Length != 0)

            {

                if (checkEtag == hashCode.ToString())

                {

                    Response.StatusCode = (int)System.Net.HttpStatusCode.NotModified;

                    Response.StatusDescription = "Not modified";

                    Response.SuppressContent = true;

                    return;

                }

            }

         

            req= System.Web.Configuration.WebConfigurationManager.AppSettings;

     

            string colrRadiantStart = req["btnBgRadiantStart"];

            string fontSize = req["btnFontSize"];

            string FontName = req["btnFontName"];

            string colrRadiantEnd = req["btnBgRadiantEnd"];

            string FontColor = req["btnFontColor"];

           

            System.Drawing.Color ocolorEnd, colorStart, colorFont ;

     

            if (colrRadiantStart != null && colrRadiantStart.Length == 6)

                colorStart = parsRgb(colrRadiantStart);

            else

                throw new HttpException("You must provide a valid btnBgColor hex rgb-code in appConfig");

     

            if (colrRadiantEnd == null || colrRadiantEnd.Length != 6)

                throw new HttpException("You must provide a valid btnBgColor hex rgb-code in appConfig");

            else

                ocolorEnd = parsRgb(colrRadiantEnd);

            if (FontColor == null || FontColor.Length != 6)

                colorFont = Color.Black; //default

            else

                colorFont = parsRgb(FontColor);

     

            int iH = int.Parse(h);

            int iW = int.Parse(w);

            Bitmap oBmp1 = new Bitmap(iW, iH);

            Graphics oGrp1 = Graphics.FromImage(oBmp1);

           

            // seems not to have effect

            oGrp1.CompositingQuality = CompositingQuality.HighQuality;

            oGrp1.InterpolationMode = InterpolationMode.HighQualityBilinear;

     

            LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0, 0, iW, iH), colorStart, ocolorEnd, LinearGradientMode.Vertical);

            oGrp1.FillRectangle(lgb, 0, 0, iW, iH);

     

            System.Drawing.FontFamily fntFam = new FontFamily(FontName);

     

            Font fnt = new Font(fntFam, float.Parse(fontSize));

            StringFormat stringFormat = StringFormat.GenericDefault;

             //we must set this value, other wise text will default to left.

            stringFormat.Alignment = StringAlignment.Center;

            SizeF szf = oGrp1.MeasureString(t, fnt, new SizeF(iW, iH), stringFormat);

            //center

            PointF FPoint = new PointF((iW - szf.Width) / 2, (iH - szf.Height) / 2);

     

            oGrp1.DrawString(t, fnt, new SolidBrush(colorFont), new RectangleF(FPoint.X, FPoint.Y, szf.Width, szf.Height), stringFormat);

     

     

     

            Response.ContentType = "image/jpeg";

            Response.Cache.SetETag(hashCode.ToString());

            //Response.Cache.SetLastModified(DateTime.Now);

            Response.Cache.SetCacheability(HttpCacheability.Public);

            oBmp1.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);               

            Response.End();

     

    }

    }
More Posts Next page »
Powered by Community Server, by Telligent Systems