How to integrate a Web application with VGWP ?

Author: admin 58 views

To integrate Visual Guard Web Portal in your web application you have to:

  • Add the assemblies of Visual Guard as references of your project.
  • Integrate Visual Guard in the code of your application.
  • Create a Visual Guard repository and declare your application using the
    Visual Guard console. This repository will contain all security items (users,
    roles, permissions …) of your application.
  • Generate the Visual Guard configuration files
    using the Visual Guard console. These configuration files will be
    needed to connect your application to the repository.
  • Grant read/write permissions to the repository.


Prerequisites:

Step 1:

Add References Web Portal

Step 2:

Add Button Go Web Portal

Step 3:

Add Button Go To Web Site 1

Step 4:

Configure Button Go To Web Site 1

Step 5:

Link Web Site To Web Portal

Step 6:

New Configuration File Of Web Portal

Step 7:

Go ToVGWeb Portal

Step 8:

Web Portal Authorized Web Site 1

Step 9:

Web Portal Authorized Web Site 2


Authenticating a user with Visual Guard Web Portal.

using Novalys.VisualGuard.Security.Membership;
using Novalys.VisualGuard.Security.Repository;
using Novalys.VisualGuard.Security.Token;

VGWebPortal portal = VGSecurityManager.Runtime.WebPortals.GetWebPortal(this.WebPortalId);
if (null != portal)
{
  String WebPortalURL = portal.Url;
  WebPortalURL = String.Concat(WebPortalURL, "?", "WReply=ReplyURL.aspx", "&", "hl=en-us");
  HttpContext.Current.Response.Redirect(WebPortalURL, true);
}

VGToken vgToken = VGSecurityManager.Runtime.Principal.Token;
if (null != vgToken)
{
  string token = vgToken.Data;
  NameValueCollection data = new NameValueCollection();
  data.Add("VGToken", token);
  RedirectAndPOST(this.Page, this.RedirectURL, data);
}

public void RedirectAndPOST(Page page, string destinationUrl, NameValueCollection data)
{
    string strForm = PreparePOSTForm(destinationUrl, data);
    page.Controls.Add(new LiteralControl(strForm));
}

private String PreparePOSTForm(string url, NameValueCollection data)
{
    string formID = "PostForm";
    StringBuilder strForm = new StringBuilder();
    strForm.Append("<form id=\"" + formID + "\" name=\"" + formID + "\" action=\"" + url + "\" method=\"POST\">");
    foreach (string key in data)
    {
        strForm.Append("<input type=\"hidden\" name=\"" + key + "\" value=\"" + data[key] + "\">");
    }
    strForm.Append("</form>");

    StringBuilder strScript = new StringBuilder();
    strScript.Append("<script language='javascript'>");
    strScript.Append("var v" + formID + " = document." + formID + ";");
    strScript.Append("v" + formID + ".submit();");
    strScript.Append("</script>");

    return strForm.ToString() + strScript.ToString();
}