About The Author
Michael Flynn is a Web Developer at Terralever, an interactive marketing agency based in Tempe, AZ. 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
<<  September 2010  >>
SMTWTFS
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

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 | Development Tips | Tips | WCF

Tags: ,

Currently rated 5.0 by 2 people

  • Currently 5/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 (11) | Post RSSRSS comment feed |

Categories: Development Tips | jQuery | Tips

Tags: , ,

Currently rated 5.0 by 2 people

  • Currently 5/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