Click or drag to resize

How to integrate Visual Guard Web Portal in Web application

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:

You must have already integrated Visual Guard.

You must have integrated the Web Portal as an application in Visual Guard Repository.

There are two ways to integrate web applications in the Visual Guard Web Portal i.e. with or without the Visual Guard Web Portal button control.

Step 1:
Open a web application in Visual Studio and add the VGWebPortalButton control into your solution in Toolbox by choosing Novalys.VisualGuard.Security.WebForm.dll. You will see the VGWebLoginForm and VGWebPortalButton controls in the toolbox.

Add References Web Portal

If the assemblies do not appear in this list you can use the Browse tab and select them in the directory Visual Guard installation directory Visual Guard Console

Step 2:

Add the Web Portal Control to your Web Application Login page and modify its properties. By default, EnableRedirect = false.

Add Button Go Web Portal
Step 3:

Customize your Web Application. For example, add the VG Web Portal

Add Button Go To Web Site 1

Step 4:

Update the properties of the VG Web Portal Button to redirect to another Web Application. i.e. EnableRedirect = &RedirectURL = http://website2

Configure Button Go To Web Site 1

 

 

Step 5:

Integrate the Web Application with the Web Portal by updating its Web Portal ID in the VG WinConsole

Link Web Site To Web Portal

 

Step 6:

Generate Visual Guard configuration files from the win console to update the VisualGuardConfiguration.config file

New Configuration File Of Web Portal

Note – Follow the same steps to setup Web Application 2

 

Step 7:

Browse the Login page of Web Application 1 and click Go to Web Portal to authenticate login user.

Go ToVGWeb Portal
Step 8:

 After successfully authenticating into the Web Console it will redirect to the URL set into the ReplyURL property or to the Web Application Default page.

Web Portal Authorized Web Site 1

 

Step 9:

Clicking Logout will redirect you to the Web Portal to reauthorize. Clicking the button (Go to Site 2) will redirect you to Another Web Application(Site 2) without logging in again.

 

Web Portal Authorized Web Site 2

Authenticating a user with Visual Guard Web Portal.

The following example demonstrates how to authenticate a user. This code can be inserted in the click event of the button in a login form:

[C#]
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);
}

The above code will redirect the user to the Visual Guard Web Portal Login page. When the user is successfully authenticated, it will redirect the user to rgz Url declared in the WReply query string.

Alternately, if you want to redirect the user to another website while logged in, you need to pass a token generated by the Web Portal and redirect by Post method.

This code can be inserted in the click event of the button in a login form:

[C#]
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);
}

 

This method will redirect user to destination Url with data by post method. This will create a literal control dynamically on page and will register javascript to submit the form.

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

 

This method will prepare javascript dynamically and will return the String to submit the form by post method. It will pass token with form.

C#
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();
}

 

See Also