Access OWA with C# inside Asp.net Site

One of my work needs was to open OWA inside our web application to make clients more related with the application and let them easy access their emails while working. After some researches i found a simple way to do that, actually it is not that much hard to find the code below, but you have to search well to find it!. An here is the way that i have done that, we have a page with 2 iframes inside it. Upper frame holds the links banner and the bottom frame which holds whatever is clicked from the links banner. The work is to open OWA inside the bottom Banner. To open OWA you have to create a small JavaScript for that which will send the user name and password to be authenticated in from owaauth.dll and if everything goes fine you'll successed to open your email. The code is as below;

public partial class OpenOwaPage : System.Web.UI.Page
{
    private string userName;
    private string passWord;

    protected void Page_Load(object sender, EventArgs e)
    {
      
            passWord = "password";
            userName ="username";
            Response.Write(CreateOWAFrom());
            Response.Write(LoadOWAPostJS("logonForm"));
      
    }

    private string LoadOWAPostJS(string strFormId)
    {
        //Constructs the JS needed to post the data to Realex and returns it
        StringBuilder strScript = new StringBuilder();
        strScript.Append("<script language='javascript'>");
        strScript.Append("var ctlForm = document.forms.namedItem('{0}');");
        strScript.Append("ctlForm.username.value=\"" + userName + "\";");
        strScript.Append("ctlForm.password.value=\"" + passWord + "\";");
        strScript.Append("ctlForm.submit();");
        strScript.Append("</script>");
        return String.Format(strScript.ToString(), strFormId);

    }

    private string CreateOWAFrom()
    {
        //Constructs the Realex HTML form and returns it
        StringBuilder strForm = new StringBuilder();
        strForm.AppendLine("<form id=\"logonForm\" name=\"logonForm\" target=\"_self\" action=\"https://your_Owa_Adress/exchweb/bin/auth/owaauth.dll\" method=\"post\">");
        strForm.AppendLine("<input type=\"hidden\" name=\"destination\" value=\"https://your_Owa_Adress/exchange/\"/>");
        strForm.AppendLine("<input type=\"hidden\" name=\"flags\" value=\"0\"/>");
        strForm.AppendLine("<input type=\"hidden\" name=\"username\" id=\"username\"/>");
        strForm.AppendLine("<input type=\"hidden\" name=\"password\" id=\"password\"/>");
        strForm.AppendLine("<input type=\"hidden\" id=\"SubmitCreds\" name=\"SubmitCreds\" value=\"Connection\"/>");
        strForm.AppendLine("<input type=\"hidden\" id=\"rdoRich\" name=\"forcedownlevel\" value=\"0\"/>");
        strForm.AppendLine("<input type=\"hidden\" id=\"rdoPublic\" name=\"trusted\" value=\"0\"/>");
        strForm.AppendLine("</form>");
        return strForm.ToString();

    }

Sometimes you maybe not able to access your OWA because of your Browser configuration, add your OWA website address to your Browser trusted site to solve this problem. If you do not want to logoff from OWA with the regular logoff button, read this (click here). Otherwise you'll enter OWA any time you type OWA address.

Hope This Helps

 

UPDATE 15/10/2010

For flexibility in exchange operations without OWA you may check http://msdn.microsoft.com/en-us/exchange/default.aspx  and down load EWS Managed API 1.0.

10 Comments

  • nice tutorial ... thanks..

  • Is this technique will work with OWA 2007 ?

    actually i have tried this but iam still getting my logon screen?

    any clue?

  • yes it does work with owa 2007, I'm using it with 2007. i do not know why you are not loggin but please check your security option on your browser. by the way, you might have hard time with Firefox! because this script do not work with firefox. getting the logon screen means that you are not authenticated yet! and some times from the browser secturiy options. Try to add your owa address to your trusted sites. if you are not able to access again you can email me from the contact page.

  • Got It Dear have to Change Some parameters :D

  • Can someone help further? It does not work for me..
    Should I copy paste into new file "as is" or need some modification?

  • you need to change this line

    your_owa_adress/.../owaauth.dll\

    you need to provide your owa address there.

    and provide a right user name and password.

  • thanks, thanks good article that really good.thanks again

  • i want to do one thing with my exchange configuration.
    from an asp.net page i want to log in to exchange server with user credential and then i want to after login page of exchange web access. so how is it possible!!
    please help me...

  • hi Ravi;
    may you explain again what you are attending to do !!! i think the post is clear..

  • Thanks for the tutorial. It IS really hard to find a reference like this. However, when I tried to access owaauth.dll on our exchanger server, I got the following message: Not all privileges referenced are assigned to the caller. Do you might have any idea how to fix this? Would this be something on the server side or is there anything we could do on the submit function? Thank you for your help.

Comments have been disabled for this content.