About The Author
Michael Flynn is a Senior Developer at Unicon, a consulting company that focuses on enterprise deployments of open source software. He specializes in web technologies that include C# .NET, SQL, XML, AJAX, jQuery, Flash, and also skills in Photoshop and Illustrator. He was been involved in web development since 1998, and earned a Bachelors and Masters degree in Computer Engineering and Computer Science from the Univerisity of Louisville and holds an MSCT certificate in Web Applications.
Calendar
<<  May 2012  >>
SMTWTFS
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

Facebook Canvas, IFrames, and Cookies

Working with iframes can be quite easy when working under the same domain, but when your project contains a cross-domain scenario it can get kind of tricky.  This article will will give a scenario of just that, but within a Facebook canvas page that needs iframe resizing, and the setting of cookies.

1. Facebook Application Setup

The first step is to create a Facebook Application.  You can do this from the Facebook Developers application page.  After you have created your application and setup all the necessary settings, we are ready to setup an iframe canvas page. 

First select the Facebook Integration tab on the left menu under your application settings.

image

The Canvas section is the section to target.  The Canvas Page is the landing page within Facebook for your application.  The Canvas URL is the canvas url that will contain your iframe, and is the landing page Facebook will display from the canvas page.  The Canvas Type needs to have IFrame selected to use an iframe within a canvas page.  The last thing that needs to be done is to select Auto-resize under IFrame Size.  This will automatically resize our iframe when the height of it increases or decreases.

image

2. Facebook Connect Setup

If we setup our settings correctly the page should be visible within Facebook.  If you were to resize the page with javascript within the iframe, Facebook wouldn’t resize the iframe to fit the page content.  The last step to accomplish this is to insert some Facebook Connect javascript. 

The old Facebook Javascript SDK is used first.  Insert the following javascript include below right after the <body> tag to initialize Facebook Connect. If this is on a secure page, Facebook also has a https version.

   1: <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US"
   2:         type="text/javascript"></script>

Then at the bottom of the site right before the </body> tag insert the following javascript.

   1: FB_RequireFeatures(["CanvasUtil"], function () {
   2:     FB.CanvasClient.startTimerToSizeToContent();
   3: });

The new Facebook Javascript SDK is used below.  This SDK uses asynchronous loading which helps out with page loads.  The code below initializes the Facebook Javascript SDK, and can be inserted at the bottom of the page right before the </body> tag.

   1: <div id="fb-root"></div>
   2: <script>   
   3:  
   4:   (function() {
   5:     var e = document.createElement('script'); e.async = true;
   6:     e.src = document.location.protocol +
   7:       '//connect.facebook.net/en_US/all.js';
   8:     document.getElementById('fb-root').appendChild(e);
   9:   }());

The last step is to add the auto resize javascript code.  The code below should be inserted after the initializing code.

   1: window.fbAsyncInit = function() {
   2:   FB.Canvas.setAutoResize();
   3: }

Now your Facebook application will resize automatically when the height of your iframe contents changes.

3. Cross Domain IFrame Cookies

Another obstacle of this project was the use of cookies being set within the iframe on Facebook.  The main culprits of the problem are Internet Explorer, Safari, and Chrome.  These browsers contain default settings that block cookies from being set within the iframe.  Internet Explorer’s problem can be solved by setting up a P3P privacy policy, but this only fixes part of the problem.  Safari and Chrome still block cookies within an iframe even with a P3P privacy policy.  Below is the preferences window from Safari 5.0 on Windows.  If the Accept cookies had Always selected then this wouldn’t be a big deal, but by default it is not, and we don’t expect our users to know this.

 

image

The only full proof way to set cookies within an a cross domain iframe is to use popups.  But beware you must do it in such a way that a popup blocker doesn’t block it.  Below is a function that opens a popup window and centers it.

   1: function openWindow {
   2:     var height = 225;
   3:     var width = 470;
   4:     var left = (screen.width/2)-(width/2);
   5:     var top = (screen.height/2)-(height/2);
   6:     mywindow = window.open("", "login","location=1,status=1,scrollbars=1,top=" + top + ",left=" + left + ",width=" + width + ",height=" + height); 
   7:  
   8:     if(mywindow == null) {
   9:         alert('Please disable your popup blocker, and try again');
  10:     }
  11:     else {
  12:         var html = "<html><body> <script> window.location = ('http://example.com/window'); </script></body></html>";
  13:         mywindow.document.write(html);
  14:     }
  15: }

So how do we stop popups?  The main thing to do is have the popup originate from a click event.  This is because a user generated action is probably safe to open since the user initiated it, but opening popups on a timer or onload event can in turn be like spamming.  You can read more about Internet Explorer pop-up blocker guidelines for more information, and other steps to avoid.

   1: <a href="#" onclick="openWindow(); return false;">Register</a>

Also by trial and error, a popup window wouldn’t open from a successful ajax call even though it originated from a click event.  The fix for this was to open the popup before the ajax call, and have some text letting the user know it is loading within the popup.  When the ajax call is finished, since the popup is already open, a call is made to reopen the popup which will use the existing one skipping any blocking functionality from the browser.

image

After the popup is open you can execute code to set your cookie within the popup.  This particular popup is setting a cookie from javascript using the JQuery cookies plugin.  After the cookie is set a call can be made to the opener page to reload the page or execute a function, and last close the popup.  The opener iframe page will keep the cookie that was set in the popup. 

   1: window.opener.callFunction();
   2: window.close();

If you are dealing with https and must call the opener page that was http then a cross domain error will occur. Here is a small trick you can do (thanks da Ritchie).  After you are done doing your logic within the https popup, you can do a redirect to the same page but replace https with http and append a query string.

   1: window.location = window.location.toString().split('?')[0].replace('https://', 'http://').replace('#', '') + '?success=true';

After the page redirects you can test for success from the url.

   1: if (window.location.toString().indexOf('?success') > -1) {
   2:     window.opener.callFunction();
   3:     window.close();
   4: }

You have officially conquered the iframe within a cross domain scenario on Facebook.

Posted on 10/4/2010 6:43:00 PM by cblaze22

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories:

Tags:

Currently rated 1.9 by 15 people

  • Currently 1.933333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Adding More Then One Service Provider For Shibboleth 2.x in IIS

I recently had to setup another environment for a website I completed.  This website would in turn be my staging site for testing.  The production website which was staging until we went live uses Shibboleth and connects to an IDP.  The staging site however needed to also replicate this, therefore I needed to configure a second Service Provider.  This process took some time and help from Google and the guys who ran the IDP.  I will go through some steps on how I achieved two service providers on one server.

1. IIS Settings

If this is a new website in IIS, you may not have the correct setting in IIS.  After installing your first SP (Service Provider), all websites should contain these settings, but if you are adding a new one you should duplicate these for your new website from an existing one that is configured to use Shibboleth, or can use Shibboleth.

Handler Mapping

First thing is to make sure you create a handler under Hander Mappings.  Select the website in IIS and your Dashboard Home should appear. Click on the icon labeled Handler Mappings.

Handler Mappings Icon

Second, click "Add Script Map…”, under the Actions panel usually to your right, for the Add Script Map window.

image

Third, type in the Request Path which is *.sso, the Executable, during installation the location was place at C:\opt\shibboleth-sp\lib\shibboleth\isapi_shib.dll, and last the name of the handler called Shibboleth.  Click OK.

image

Technorati Tags: ,

The Shibboleth handler has now been added, and can see the result below under the Handler Mappings listing.

image

ISAPI Filter

The last addition to in IIS it under the ISAPI Filters section under Dashboard Home, but clicking the ISAPI Filters icons.

image

Second, click "Add…”, under the Actions panel usually to your right, for the Add ISAPI Filter window.

image

Third, type in the Filter name which is called Shibboleth, and last the Executable which is the same location as the Handler Mapping above. Click OK.

image

The Shibboleth ISAPI Filter has now been added, and can see the result below under the ISAPI Filters listing.

image

2. Generate Certificate/Private Key

The second part is to generate a new certificate/private key pair.  The certificate will be given to the IDP to register your SP.  To generate a new pair head to the Shibboleth folder, and find the kengen.bat file.  This uses opensll to generate a certificate and private key.  These will be used by both the IDP and SP to validate the requests that come through.  Make sure not to override your existing certificate and private key for the first site you configured.  The files are usually sp-cert.pem  and sp-key.pem by default.  Once generated this certificate and private key will be used in the next step.

image

3. Update Shibboleth Configuration File

The next step is to update the configuration file for your new service provider.  Location the directory where shibboleth2.xml  is located.  This configuration file was located at C:\opt\shibboleth-sp\etc\shibboleth\.

Once opened locate the ISAPI node that contains your site nodes.

<ISAPI normalizeRequest="true" safeHeaderNames="true">
  <Site id="1" name="example.com" /> 
  <Site id="2" name="staging.example.com" />
</ISAPI>

Insert your new Site node.  My new node is staging.example.com, with an id of 2.  The id of the Site element comes from IIS.  If you select Sites under IIS, you will get a listing of all your websites including the site id. 

image

image

The second step in the configuration file is to add a new host entry, under the RequestMapper section.  The only difference from your original host entry is the host entry needs a applicationId and the new name attribute.

<RequestMapper type="Native">
    <RequestMap applicationId="default">
        <Host name="example.com">
          <Path name="secure" authType="shibboleth" requireSession="true" /> 
      </Host>
        <Host applicationId="staging" name="staging.example.com">
            <Path name="secure" authType="shibboleth" requireSession="true" /> 
        </Host>
    </RequestMap>
</RequestMapper>

The last section in the configuration section that needs to be edited is the ApplicationDefaults section.  A new section called ApplicationOverride needs to be added. This was added at the end of this section.  This was given to me by the IDP, so some attributes might be different. 

<ApplicationOverride id="staging" entityID="https://staging.example.com">
  <Sessions lifetime="28800" timeout="3600" checkAddress="false" handlerURL="https://staging.example.com/Shibboleth.sso" handlerSSL="false" idpHistory="false" idpHistoryDays="7" /> 
  <CredentialResolver type="File" key="sp-staging-key.pem" certificate="sp-staging-cert.pem" /> 
</ApplicationOverride>
 

Since the configuration file is in the same folder as the new certificate/private key pair files we generated, the file names are just added to the CredentialResolver  element as attributes called key and certificate. The entityID is also important as that will be given to the IDP as the key for your Service Provider. 

4. Register With IDP

The last step is to register your Service Provider with your IDP.  The information that will need to be sent to the IDP is the certificate that was generated (not the private key), and the entityID from the ApplicationOverride section of the configuration file we edited.

5. Test The Connection

Like with your first Shibboleth configuration, setup a page that will redirect to the IDP login page, and make sure a valid redirect happens after a correct login.  If you have any issues check the log files under the C:\opt\shibboleth-sp\var\log\shibboleth folder.  This can give valuable information on why your configuration isn’t working.

Posted on 9/22/2010 1:16:02 AM by cblaze22

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: IIS | Shibboleth

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Microformats .NET Toolkit - hCard, hCalendar and XFN

I recently got fascinated by Microformats.  Not sure why but its a neat concept that is catching on as Microsoft and Google are taking notice.  I recently wanted to create an easy way to render the most common Microformats, the hCard and hCalendar.  There are so many properties that one can assign it would be very hard to remember what goes where, misspelling, or even an existing property you didn't know existed.  Microformats are adding additions all the time so this would be perfect for someone who didn't want to memorize and check the Microformats website periodically for them. Below is the rendering of three controls I created for this toolkit.

 

hCalendar

Terralever Office Upgrade Bash!
5/7/2009
Tempe Arizona
http://www.terralever.com
Come check out Terralever's new digs and help us celebrate our growth as we officially unveil our new location!

hCard

N 48° 81.6667 E 2° 36.6667
home: 555-555-5555
work: 444-444-4444
Microsoft Outlook
Terralever
dom
425 S. Mill Avenue
Suite 201
Tempe AZ 85281
US

XFN

Terralever

 The control structure is also below.  I have seen some controls developers had made, and they do the job but they are not scalable.  I wanted to create a control that was scalable, and shared common properties. Below is the hCalendar, hCard, and XFN control.  You can read about all these on the Microformats website.

hCalendar

<mf:hCalendar runat="server" ID="hCalendar">
        <Properties>
            <mf:Summary Value="Terralever Office Upgrade Bash!" />
            <mf:DateCollection>
                <Dates>
                    <mf:StartDate DateTime="5/7/2009" />
                </Dates>
            </mf:DateCollection>
            <mf:Location Value="Tempe Arizona" />
            <mf:Url Value="http://www.terralever.com" />
            <mf:Description Value="Come check out Terralever's new digs and help us celebrate our growth as we officially unveil our new location!" />
        </Properties>
    </mf:hCalendar>

hCard

 <mf:hCard ID="hCard" runat="server">
        <Properties>
            <mf:CardGeo>
                <Coordinates>
                    <mf:Latitude Text="N 48° 81.6667" Value="48.816667" />
                    <mf:Longitude Text="E 2° 36.6667" Value="2.366667" />
                </Coordinates>
            </mf:CardGeo>
            <mf:NameCollection>
                <Names>
                    <mf:Name PreferredName="true" Url="http://www.terralever.com" HtmlTag="Div">
                        <NamePropertyCollection>
                            <mf:NameProperty Type="HonorificPrefix" Value="Mr." />
                            <mf:NameProperty Type="GivenName" Value="Michael" />
                            <mf:NameProperty Type="AdditionalName" Value="Saul" />
                            <mf:NameProperty Type="FamilyName" Value="Flynn" SortString="true" />
                            <mf:NameProperty Type="HonorificSuffix" Value="Jr." />
                        </NamePropertyCollection>
                    </mf:Name>
                </Names>
            </mf:NameCollection>
            <mf:TeleCommunicationCollection>
                <TeleCommunications>
                    <mf:Telephone Type="Home" Value="555-555-5555" Preferred="true" />
                    <mf:Telephone Type="Work" Value="444-444-4444" />
                    <mf:Email Type="Internet" Value="mikef@terralever.com" Preferred="true" />
                    <mf:Mailer Value="Microsoft Outlook" />
                </TeleCommunications>
            </mf:TeleCommunicationCollection>
            <mf:CompanyCollection List="true">
                <Companies>
                    <mf:Company PreferredName="false" Name="Terralever" HtmlTag="Div" Url="http://www.terralever.com">
                        <AddressCollection>
                            <Addresses>
                                <mf:Address Type="Domestic" StateCode="true" CountryCode="true">
                                    <AddressContainerCollection>
                                        <mf:AddressContainer>
                                            <AddressPropertyCollection>
                                                <mf:AddressProperty Type="StreetAddress" Value="425 S. Mill Avenue" HtmlTag="Div" />
                                                <mf:AddressProperty Type="ExtendedAddress" Value="Suite 201" HtmlTag="Div" />
                                            </AddressPropertyCollection>
                                        </mf:AddressContainer>
                                        <mf:AddressContainer HtmlTag="Div">
                                            <AddressPropertyCollection>
                                                <mf:AddressProperty Type="Locality" Value="Tempe" HtmlTag="Span" />
                                                <mf:AddressProperty Type="Region" Value="Arizona" HtmlTag="Span" />
                                                <mf:AddressProperty Type="PostalCode" Value="85281" HtmlTag="Span" />
                                            </AddressPropertyCollection>
                                        </mf:AddressContainer>
                                        <mf:AddressContainer>
                                            <AddressPropertyCollection>
                                                <mf:AddressProperty Type="CountryName" Value="United States" HtmlTag="Div" />
                                            </AddressPropertyCollection>
                                        </mf:AddressContainer>
                                    </AddressContainerCollection>
                                </mf:Address>
                            </Addresses>
                        </AddressCollection>
                    </mf:Company>
                </Companies>
            </mf:CompanyCollection>
            <mf:MessagingCollection>
                <Messaging>
                    <mf:IMPP Type="AIM" InstantMessageName="cblaze22@gmail.com" />
                    <mf:IMPP Type="MSN" InstantMessageName="mikef@terralever.com" />
                </Messaging>
            </mf:MessagingCollection>
        </Propert

XFN

<mf:XFNLink ID="xfn" runat="server" Text="Terralever" NavigateUrl="http://www.terralever.com">
        <XFN Family="Parent"></XFN>
    </mf:XFNLink>

 

You can download the toolkit below

Microformats.NET.zip (157.63 kb)

Posted on 7/13/2009 4:28:00 PM by cblaze22

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: ASP.NET | Server Controls | Microformats

Tags:

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

URL Rewriting In Joomla 1.5 on IIS 7

I recently completed a project that needed to have Joomla use SEO friendly URL's on IIS 7.  The main goal was to get this to work with Microsoft URL Rewrite Module for IIS 7.0 Go Live. Doing some research I could not find any tutorials on this, or if anyone had succeeded.  Joomla is PHP based and Apache friendly and I am a .NET Developer so I hope you felt my pain through this learning process.  Joomla has built in SEF (Search Engine Friendly) functionality but works flawlessly on Apache, IIS on the other hand it is a different story.  Joomla uses the htaccess file if the website resides on an Apache server.  IIS doesn't use the htaccess file and therefore can not get the desired results we want.

Joomla Configuration

 

Default Joomla URL


http://www.mydotnetworld.com/index.php?option=com_content&task=view&id=5&Itemid=1

This disadvantage of this url is it is long, hard to read to the human eye, and not search engine friendly, meaning it might never be indexed.

SEF Joomla URL (htaccess disabled)

http://www.mydotnetworld.com/index.php/content/view/5/6/

To enable this you can log into the admin and navigate to Site > Global Configuration.  On the right side you will see a area called "SEO Settings".  Turn "Search Engine Friendly Urls" to on. 

The disadvantage to this approach is it had index.php in the url.  I have read somewhere that it doesn't hurt search engine indexing, which may be true, but if you can fix that for user display it is a must.

SEF Joomla URL (htaccess enabled)

http://www.mydotnetworld.com/content/view/5/6/

If you want to remove the index.php from the URL and you are on Apache you may select the second option under "SEO Settings".  Ignore the warning by "Use Apache mod_rewrite" and turn it on.  I haven't tested this on Apache but it seems to remove the index.php mysteriously as I do not have much knowledge of PHP and how Joomla removes this.  IIS does not have the ability to read the htaccess file, and rewrite rules in it.

SEF Joomla URL with SH404SEF (htaccess enabled)

http://www.mydotnetworld.com/philosophy/marketing/web-strategy

I tried numerous plugins but could not get the desired result I wanted.  The one I finally got working was SH404SEF.  As you can see the above url is much cleaner and easier to read.  This result was accomplished from the above steps.  Yes, even turning on the htaccess option.  When installing this plugin make sure it is enabled.

The last step is to enable the actual rewriting of the page to the correct URL.  I copied the rules from the htaccess file provided by Joomla.  The bold one I could not import into IIS as it could not read the syntax, but works regardless of this rule.  So if anyone has a work around please add a comment.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]


IIS 7 Configuration



I know there are ISASPI filter work around's available but I wanted to see if I could get this to work with the new plugin available for IIS, called Microsoft URL Rewrite Module for IIS 7.0 Go Live

You will need to install the Microsoft URL Rewrite Module for IIS 7.0 Go Live and FastCgi.  Go to your website directory in IIS and make sure you are in features view.  Double click the "URL Rewrite" icon under the IIS section.



Once in the url rewrite section there is an option to "Import rules..." on the sidebar.



Within the textbox that says "Rewrite rules", paste the rules from above that were taken from the htaccess file found in the Joomla base directory. Click apply.  IIS is now set to do URL rewriting for Joomla.



After much searching and reading this is the configuration I came up with to get Joomla to have SEO friendly URL's on IIS 7 and the Go Live Rewrite Module.

Posted on 10/24/2008 1:50:00 AM by cblaze22

Permalink | Comments (39) | Post RSSRSS comment feed |

Categories: Url Rewriting | Joomla | IIS

Tags: , ,

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Use a WCF Service with HTTP and HTTPS in C#

I had a problem with a WCF service that was having problems on a secure page using SSL.  The error said the endpoint could not be found.  I found some resources on making a service HTTPS ready, but not for both.  I finally figured it out that I need two endpoints pointing to the same service.  One endpoing contained another property called "bindingConfiguration" that maps a binding that has a mode of transport which enables an endpoint for https.  The bolded text below is what you need to enable a service for HTTPS.

   

<system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

    <behaviors>

        <endpointBehaviors>

            <behavior name="WebServicesBehavior">

                <webHttp/>

            </behavior>

        </endpointBehaviors>

    </behaviors>

    <services>

        <service name="WebService">

            <endpoint binding="webHttpBinding" contract="IWebService" behaviorConfiguration="WebServicesBehavior"/>

            <endpoint binding="webHttpBinding" bindingConfiguration="webBinding" contract="IWebService" behaviorConfiguration="WebServicesBehavior"/>

        </service>

    </services>

    <bindings>

        <webHttpBinding>

            <binding name="webBinding">

                <security mode="Transport">

                    <transport clientCredentialType="None"/>

                </security>

            </binding>

        </webHttpBinding>

    </bindings>

</system.serviceModel>

Posted on 10/18/2008 12:54:00 AM by cblaze22

Permalink | Comments (3) | Post RSSRSS comment feed |

Categories: ASP.NET | ASP.NET | Development Tips | Development Tips | Tips | Tips | WCF | WCF

Tags: , , ,

Currently rated 3.2 by 6 people

  • Currently 3.166667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Http To Https And Back with a Basepage in ASP.NET C#

I needed to have one page redirect to a https protocol, and when leaving that page go back to the http protocol.  I wanted a easy way that would be handled in one place, but have the ability to be overridden when necessary.  I always create a basepage for all my pages, so I decided to create a method that a page can override.  I have a page called checkout.aspx that needs to have https, so I override the parent class to redirect it to the https page.  If the user leaves the page, they will then be redirected back to http with the basepage implementation.

Basepage.cs

public virtual void SetProtocol()

{

    if (Request.ServerVariables["HTTPS"].ToString().ToLower() == "on")

    {

        string url = string.Format("http://{0}{1}", HttpContext.Current.Request.Url.Authority, Request.RawUrl);

        Response.Redirect(url, true);

    }

}

 

protected override void OnInit(EventArgs e)

{

    SetProtocol();

    base.OnInit(e);

}

 

 

 

Checkout.cs

 

public override void SetProtocol()

{

    if (Request.ServerVariables["HTTPS"].ToString().ToLower() == "off")

    {

        string url = string.Format("{0}/checkout", Utility.RootUrl).Insert(4, "s");

        Response.Redirect(url, true);

    }

}

 

protected void Page_Load(object sender, EventArgs e)

{

    SetProtocol();

}

Posted on 9/25/2008 11:05:00 PM by cblaze22

Permalink | Comments (1) | Post RSSRSS comment feed |

Categories: ASP.NET | Development Tips | Tips

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Validation Summary For Multiple User Controls in C# ASP.NET

I was looking for a simple way to have the convenience of self contained controls, but still use a single validation summary.   I created a base class for user controls so code can be reused without repeating it and a property called ValidationGroup that finds all validation controls in the control and assigns the validation group to them.

public class BaseControl : UserControl
{
    public BaseControl()
    {

    }

    public virtual string ValidationGroup
    {
        set
        {
            foreach (Control control in this.Controls)
            {
                if (control is BaseValidator)
                {
                    ((BaseValidator)control).ValidationGroup = value;
                }
            }
        }
    }
}

Below is an example of a validation summary and a user control called address that finds all controls within it to use the validation group of the validation summary.

<asp:ValidationSummary CssClass="validationSummary" runat="server" ID="ValidationSummary"
    ValidationGroup="vgEvent"  /> 

 <uc:Address ID="CalendarAddress" runat="server" ValidationGroup="vgEvent" />

Posted on 9/22/2008 12:44:00 AM by cblaze22

Permalink | Comments (3) | Post RSSRSS comment feed |

Categories: ASP.NET | Development Tips | Tips | User Controls

Tags: ,

Currently rated 4.0 by 2 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Open Link From IFrame Into New Window with JQuery

I recently had to open links in an IFrame in a new window.  The problem before was files ilke PDFs and images were opening up in the IFrame with no scrolling.  I wanted a clean, quick solution with JQuery so below is what I came up with. 

$(document).ready(function() {
        $('a').click(function() {
        window.open($(this).attr('href'), 'File', 'fullscreen=yes', 'resizable,scrollbars'); return false;
    });
});

Posted on 9/13/2008 8:03:00 PM by cblaze22

Permalink | Comments (12) | Post RSSRSS comment feed |

Categories: Development Tips | jQuery | Tips

Tags: , ,

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Universal Root/Base Url

I have tried many ways to get the root/base url of a website.  A static approach to this is to store it in the web.config appsettings section and calling it in code.

<appSettings>
        <add key="RootUrl" value="http://www.mydotnetworld.com"/>
</appSettings>

string rootUrl = ConfigurationManager.AppSettings["RootUrl"];

This isnt convenient when you are working locally and the port number might change.  Another way is to call a method to get the base/root of the website.  I have seen numerous ways to do this and most of them had flaws.  I created my own that I use in every project and hasnt failed me yet.  It works in any development environment.

public static string RootUrl
{
    get
    {
        HttpContext context = HttpContext.Current;
        string executionPath = context.Request.ApplicationPath;
        return string.Format("{0}://{1}{2}", context.Request.Url.Scheme,
                                                                context.Request.Url.Authority,
                                                                executionPath.Length == 1 ? string.Empty : executionPath);
    }
}

I place this function inside a utility class and call it wherever the base/url is needed.  It also comes in handy within javascript.

var rooUrl = <%= Utility.RootUrl %>;

Posted on 8/16/2008 2:14:00 AM by cblaze22

Permalink | Comments (1) | Post RSSRSS comment feed |

Categories: ASP.NET | Development Tips

Tags:

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Export A Website Template In Visual Studio

As a web developer consistency and organization is a key factor in efficient, scalable and maintainable projects.  Visual Studio has a nice little feature called Export Template Wizard that will create templates which future projects can be based upon.  I use this tool to create website structures I use over and over, without searching and adding items at the start of the project or during the website development process.  Everything will be available to me in a consistent structure every project.

Create Website

Creating a reusable template first starts with creating a new website and adding the necessary elements that are used in every project.  I have a seperate folder where I keep this template for later user or adding or deleting items in the future and recreating the template.  This post is using Visual Studio 2008.  Some items used in this template are listed below:

  • robots.txt
  • sitemap.xml
  • web.config
  • web.sitemap
  • global.asax
  • masterpage.master
  • stylesheet.css
  • reset.css
  • forms.css
  • basepage.cs
  • utility.cs
  • cssfriendly.dll

I also included pre-existing folders

  • App_Browsers
  • App_Code
  • App_Data
  • App_Themes
    • Default
      • Images
  • Assets
  • Bin
  • Script

What you include depends on your preference.  If you have any suggestions please leave a comment.

 

Export Template

The next step is to export this template to a zip file for reuse in Visual Studio.   Navigate to 'File' > 'Export Template...'

If this is not available which most likely it isn't, right click at the top of Visual Studio near the menu or toolbars and you get a long list of toolbar selections. 

Select 'Customize...' at the very bottom.  The 'Customize' dialog will appear. 

You should be on the 'Command' tab. 

Select 'File' from the 'Categories' list box. 

Under the 'Commands' listbox select and drag 'Export Template...' to the 'File' menu and drop it anywhere. 

We now can export our website to a reusable template.


Export Template Wizard

A dialog window called 'Export Template Wizard'  will appear to 'Choose Template Type'

Make sure the 'Project template' radio button is selected. 

Next select from the 'From which project would you like to create a template?' dropdown select the template we are going to export from the solution. 

Last select the language you would like this template to be from the 'What language category should this template appear under in the New Project dialog box?' dropdown.

Click 'Next >'.

 Next we need to Select Template Options.

Options include choosing a Template icons, Template name, Template description, Automatically import the template into Visual Studio, and Display an explorer window on the output files folder.

Input your necessary options and click Finish.

Windows explorer will now open to the My Exported Templates folder in windows explorer, displaying a zip file that contains all the files of you website template. 


Import Website Template

After creating our website template we can now put it to use.  Create a new website in Visual Studio.   Look under the heading My Templates for the name of the template you created and click the OK button.  Our website templated is loaded with the structure we want and ready to use by your development team.

Conclusion

Looking at many websites with different stuctures can be very frusturating and at times can be time intensive especially on time sensitive projects.  Visual Studio offers a nice way to counter this by offering the ability to create your own templates without the need of searching for necessary files that are used in every project and remembering where they should go.

Download - Website Template.zip (129.88 kb)

Posted on 8/10/2008 3:18:00 PM by cblaze22

Permalink | Comments (17) | Post RSSRSS comment feed |

Categories: Visual Studio

Tags:

Currently rated 5.0 by 6 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5