在日常开发过程中难免碰到些古怪的需求,以至于Dynamics CRM提供的标准功能都无法完成该功能。这个时候选择开发自定义页面就是个不错的选择,通过使用ASP.NET来构建灵活的Web页面并调用Dynamics CRM中提供的API就能开发出满足一切需求的Web页面。
我们来制作一个简单的例子吧,在这个页面中将会显示当前登录用户的所有信息。
操作步骤
图1
图2
图3
图4
使用到的代码
WhoAmI.aspx
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WhoAmI.aspx.cs" Inherits="WhoAmI" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div id="display" runat="server"> </div> </form> </body> </html>
WhoAmI.aspx.cs
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55using System; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Net; using System.Net.Security; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Description; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk.Messages; using Microsoft.Xrm.Sdk.Discovery; using Microsoft.Xrm.Sdk.Client; using Microsoft.Crm.Sdk.Messages; public partial class WhoAmI : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { WhoAmIRequest request = new WhoAmIRequest(); IOrganizationService service = GetService(); WhoAmIResponse response = (WhoAmIResponse)service.Execute(request); Guid userId =response.UserId; Entity curUser = service.Retrieve("systemuser", userId, new ColumnSet { AllColumns = true }); string displayMsg ="当前用户的登录信息如下:<br>"; foreach (var attr in curUser.Attributes) { displayMsg+=attr.Key+" : "+attr.Value.ToString()+"<br>"; } display.InnerHtml=displayMsg; } private IOrganizationService GetService() { Uri orgUri = new Uri(ConfigurationManager.ConnectionStrings["svcurl"].ConnectionString); OrganizationServiceProxy service; System.ServiceModel.Description.ClientCredentials credentials = new ClientCredentials(); credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; service = new OrganizationServiceProxy(orgUri, null, credentials, null); service.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); return service; } }
Web.config
复制代码
1
2
3
4
5
6
7
8
9
10
11
12<?xml version="1.0"?> <configuration> <connectionStrings> <add name="svcurl" connectionString="http://localhost:8110/test/xrmservices/2011/organization.svc"/> </connectionStrings> <system.web> <compilation debug="false" targetFramework="4.0" /> </system.web> </configuration>
小贴士
1.你可以将WhoAmI.aspx和WhoAmI.aspx.cs进行编译处理,并将编译好的Dll文件放在Dynamics CRM安装目录下的Bin文件中。然后将WhoAmI.aspx和Web.config文件放在ISV目录下,和本博文介绍的一样。这样我们就可以通过这样的URL"http://server/organizationname/isv/whoami.aspx",来访问自定义页面了。
最后
以上就是闪闪哈密瓜最近收集整理的关于Dynamics CRM 2011 编程系列(29):自定义页面的全部内容,更多相关Dynamics内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复