CRM 2011 + get Page url in Plugin Code
-
2011. április 5. 7:10
Hi,
now i doing application by Microsoft Dynamic CRM 2011, in one senario i have to find Page url in PLUG-IN Code , is it Possible. if possible please send suitable solution with Example....
Thanks and Regards,
Elanji- Áthelyezte: Donna EdwardsMVP, Owner 2011. április 9. 15:23 (From:CRM)
Az összes válasz
-
2011. április 5. 7:36
You can use HttpContext to obtain the page information.
HttpContext webContext = HttpContext.Current;
if (webContext != null)
{
string url = webContext.Request.Path;
}Gendral scenario example. Same Plugin Execute method is called for both when "Advanced Find" data is fetched and "Export to Excel" option is done. In order to differentiate betwwn both the events you can use HttpContext to identify the url and proceed on.
Hope this helps.
-
2011. április 5. 9:29
Hi Vinoth ,
Thank for ur quick reply, i could able to find url, but it shows only page url which we will able to see on address bar. but i want actual url [ Example in every page url is Same like "********/main.aspx# , but in reality is while we click on left navigation page goto the actual url [ It contain Entity type code etc,] so i want to this actual URL, shall we find through plugin code? if we able to get , send suitable Solution with example...
thanks and regards,
Elanji -
2011. április 9. 15:23Tulajdonos
-
2011. április 9. 18:54
You can always get the entity ID from the plugin, and build the URL at runtime. You would probably have to do something like this:
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
Entity entity;
if (context.InputParameters.Contains("Target") &&context.InputParameters["Target"] is Entity)
{
entity = (Entity)context.InputParameters["Target"];
}
else
{
return;
}
try
{
var webContext = HttpContext.Current;
if (webContext != null)
{
string url = webContext.Request.Path;
}
var id = entity.Id;
url = url + "?Id=" + id; // build the query string at runtime, you probably have to add objecttypecode and other parameters here as well
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}- Válasznak javasolta: Torstein Utne 2011. április 11. 9:44
-
2012. június 6. 18:33
Hello Elanji:
By using this code, you will get the base url of the record.
HttpContext webContext = HttpContext.Current;
if (webContext != null)
{
string url = webContext.Request.Path;
}Now as you are worried that how to get entity code and construct the url,
so for your information, we can replace entity code with entity name
so just use 'etn=entityname' in place of'etc=entitycode'
Entity name you can get from currentContext.EntityName
Now, you need current record Id, that you can get from currentContext.PrimaryEntityID.
You have now all the things to construct a record URL without hard-coding anything.
Enjoy...:)
Saurabh Gupta, MS CRM 2011 Software Development Engineer
- Válasznak javasolta: SaurabhGupta_2160 2012. június 6. 18:33
-
2012. június 16. 3:53
Hi,
Just to add, if we are using HttpContext (i.e. System.Web dll) in case of CRM 2011 Online Sandboxed plugin we might recieve "SecurityException : The assembly does not allow partially trusted callers".
Regards,
Nishant Rana
http://nishantrana.wordpress.com
https://twitter.com/#!/nishantranacrm
- Szerkesztette: Nishant RanaMicrosoft Employee 2012. június 16. 3:57