AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 14.07.2009, 08:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
mscrm4ever: CRM 4.0 Logging user login information
Источник: http://mscrm4ever.blogspot.com/2009/...formation.html
==============



Following is a simple example on how-to log a user interaction with CRM. The sample uses a simple plug-in that references the System.Web assembly. Once you create a reference to this assembly you’re able to read the HttpContext and consequently read the information you wish to log.


The plug-in hooks into the execute message which in most cases is the first event to fire (grid event). The plug-in also writes a cookie back to the browser to mark the logging operation so it only happens once while the main crm application is opened.


In the example I also create a simple logInfo entity with fields I’m interested in logging.


Please not that while reading information from the httpcontext and other objects like Request might be considered supported, reading information that CRM uses like httpcontext.items[“organizationName”] or writing information to a cookie might break your support. So when you write values back to the browser make sure you’re using a well defined naming convention that will always stay unique. And instead of reading the orgname from the items collection get it from the request url.



using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using System.Web;

namespace GI.SandBox
{
public class LoginHandler : IPlugin
{
#region IPlugin Members

public void Execute(IPluginExecutionContext context)
{
if (context.MessageName != "Execute")
{
return;
}

if (context.Stage != MessageProcessingStage.BeforeMainOperationOutsideTransaction)
{
return;
}

if (!(context.CallerOrigin is ApplicationOrigin))
{
return;
}

HttpContext webContext = HttpContext.Current;
HttpCookie logInfo = webContext.Request.Cookies.Get("loginfo");

if (logInfo == null)
{
DynamicEntity logInfoEntry = new DynamicEntity();
logInfoEntry.Name = "gi_loginfo";

logInfoEntry.Properties.Add
(
new StringProperty
(
"gi_userhostaddress",
webContext.Request.UserHostAddress
)
);

logInfoEntry.Properties.Add
(
new StringProperty
(
"gi_useridentity",
webContext.User.Identity.Name
)
);

logInfoEntry.Properties.Add
(
new StringProperty
(
"gi_starturl",
webContext.Request.Path
)
);

logInfoEntry.Properties.Add
(
new StringProperty
(
"gi_hostname",
webContext.Request.Url.Host
)
);

if (webContext.Items["organizationName"] != null)
{
logInfoEntry.Properties.Add
(
new StringProperty
(
"gi_userhostaddress",
webContext.Items["organizationName"].ToString()
)
);
}

logInfoEntry.Properties.Add
(
new CrmDateTimeProperty
(
"gi_datetime",
new CrmDateTime(webContext.Timestamp.ToString())
)
);

TargetUpdateDynamic targetRecord = new TargetUpdateDynamic();
targetRecord.Entity = logInfoEntry;

UpdateRequest updateRequest = new UpdateRequest();
updateRequest.Target = targetRecord;

context.CreateCrmService(true).Execute(updateRequest);

logInfo = new HttpCookie("loginfo");
logInfo.Value = DateTime.Now.ToString();
webContext.Response.Cookies.Add(logInfo);
}
}

#endregion
}
}



Источник: http://mscrm4ever.blogspot.com/2009/...formation.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
mscrm4ever: CRM 4.0 Embedding User Signature in CRM Web Client Blog bot Dynamics CRM: Blogs 0 31.05.2009 06:07
Microsoft Dynamics CRM Team Blog: Building Rich-Client Dashboards for Microsoft Dynamics CRM with Windows Presentation Foundation Blog bot Dynamics CRM: Blogs 1 31.03.2009 13:24
Microsoft Dynamics CRM Team Blog: List Web Part for Microsoft Dynamics CRM 4.0 Deployment Scenarios Blog bot Dynamics CRM: Blogs 0 30.01.2009 22:05
Microsoft Dynamics CRM Team Blog: Microsoft Dynamics CRM 4.0 Bookshelf Blog bot Dynamics CRM: Blogs 1 22.01.2009 04:46
Microsoft Dynamics CRM Team Blog: Troubleshooting the Microsoft Dynamics CRM E-mail Router Blog bot Dynamics CRM: Blogs 0 09.01.2009 06:03

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 11:17.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.