forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.xml
412 lines (339 loc) · 21.6 KB
/
User.xml
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<Type Name="User" FullName="Microsoft.VisualBasic.ApplicationServices.User">
<TypeSignature Language="C#" Value="public class User" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi User extends System.Object" />
<TypeSignature Language="DocId" Value="T:Microsoft.VisualBasic.ApplicationServices.User" />
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>Provides access to the information about the current user.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The properties and methods exposed by the `My.User` object provide access to the information about the current user. The meaning of "current user" differs slightly between Windows and Web applications. In a Windows application, the current user is the user who runs the application. In a Web application, the current user is the user who accesses the application.
The `My.User` property also provides access to the <xref:System.Security.Principal.IPrincipal> for the current user. A principal object represents the user's security context, including that user's identity and any roles to which the user belongs.
For Windows applications, this property provides the same functionality as the <xref:System.Threading.Thread.CurrentPrincipal%2A> property. For Web applications, this property provides the same functionality as the <xref:System.Web.HttpContext.User%2A> property of the object returned by the <xref:System.Web.HttpContext.Current%2A> property.
> [!NOTE]
> For Windows applications, only projects built on the **Windows Application** template initialize the `My.User` object by default. In all other Windows project types, you must initialize the `My.User` object by calling the <xref:Microsoft.VisualBasic.ApplicationServices.User.InitializeWithWindowsUser%2A> method explicitly or by assigning a value to <xref:System.Threading.Thread.CurrentPrincipal%2A>.
> [!NOTE]
> The `My.User` object cannot report information about the current Windows user when run under Windows 95 and Windows 98 because those operating systems do not support the concept of a logged-on user. You must implement custom authentication to use the `My.User` object on those operating systems.
## Examples
This example checks if the application is using Windows or custom authentication, and uses that information to parse the `My.User.Name` property.
[!code-vb[VbVbalrMyUser#3](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrMyUser/VB/Class1.vb#3)]
]]></format>
</remarks>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public User ();" />
<MemberSignature Language="ILAsm" Value=".method public specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.ApplicationServices.User.#ctor" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:Microsoft.VisualBasic.ApplicationServices.User" /> class.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The properties and methods exposed by the `My.User` object provide access to information about the current user.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="CurrentPrincipal">
<MemberSignature Language="C#" Value="public System.Security.Principal.IPrincipal CurrentPrincipal { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Security.Principal.IPrincipal CurrentPrincipal" />
<MemberSignature Language="DocId" Value="P:Microsoft.VisualBasic.ApplicationServices.User.CurrentPrincipal" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Security.Principal.IPrincipal</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the current principal (for role-based security).</summary>
<value>A <see cref="T:System.Security.Principal.IPrincipal" /> value representing the security context.</value>
<remarks>
<format type="text/markdown"><]
]]></format>
</remarks>
<exception cref="T:System.Security.SecurityException">The caller does not have the permission required to set the principal.</exception>
<permission cref="T:System.Security.Permissions.SecurityPermission">Describes a set of security permissions applied to code. Associated enumeration: <see cref="F:System.Security.Permissions.SecurityPermissionFlag.ControlPrincipal" />.</permission>
</Docs>
</Member>
<Member MemberName="InitializeWithWindowsUser">
<MemberSignature Language="C#" Value="public void InitializeWithWindowsUser ();" />
<MemberSignature Language="ILAsm" Value=".method public instance void InitializeWithWindowsUser() cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.ApplicationServices.User.InitializeWithWindowsUser" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Sets the thread's current principal to the Windows user that started the application.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
You can use the `My.User.InitializeWithWindowsUser` method to set the thread's current principal to the Windows user that started the application. The Visual Basic Application Model in a Windows application calls this method at startup by default. In other project types, you must set the thread's current principal by calling this method explicitly or by assigning a value to <xref:System.Threading.Thread.CurrentPrincipal%2A?displayProperty=fullName>.
In Windows projects, the `My.User` object is based on the thread's current principal; therefore, this method can change the information `My.User` returns. In an ASP.NET application, the `My.User` object is based on the current HTTP request's user identity, and is unaffected by this method.
> [!NOTE]
> The exact behavior of the `My.User` object depends on the type of application and on the operating system on which the application runs. For more information, see the <xref:Microsoft.VisualBasic.ApplicationServices.User> class overview.
This is an advanced member; it does not show in IntelliSense unless you click the **All** tab.
## Availability by Project Type
|Project type|Available|
|-|-|
|Windows Application|**Yes**|
|Class Library|**Yes**|
|Console Application|**Yes**|
|Windows Control Library|**Yes**|
|Web Control Library|**Yes**|
|Windows Service|**Yes**|
|Web Site|**Yes**|
]]></format>
</remarks>
<permission cref="T:System.Security.Permissions.SecurityPermission">Describes a set of security permissions applied to code. Associated enumeration: <see cref="F:System.Security.Permissions.SecurityPermissionFlag.ControlPrincipal" />.</permission>
</Docs>
</Member>
<Member MemberName="InternalPrincipal">
<MemberSignature Language="C#" Value="protected virtual System.Security.Principal.IPrincipal InternalPrincipal { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Security.Principal.IPrincipal InternalPrincipal" />
<MemberSignature Language="DocId" Value="P:Microsoft.VisualBasic.ApplicationServices.User.InternalPrincipal" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Security.Principal.IPrincipal</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the principal object representing the current user.</summary>
<value>An <see cref="T:System.Security.Principal.IPrincipal" /> object representing the current user.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
In the <xref:Microsoft.VisualBasic.ApplicationServices.User> object, this property wraps the <xref:System.Threading.Thread.CurrentPrincipal%2A?displayProperty=fullName> property. Override this method in a derived class to provide different behavior. For example, the <xref:Microsoft.VisualBasic.ApplicationServices.WebUser.InternalPrincipal%2A?displayProperty=fullName> property overrides this property.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="IsAuthenticated">
<MemberSignature Language="C#" Value="public bool IsAuthenticated { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool IsAuthenticated" />
<MemberSignature Language="DocId" Value="P:Microsoft.VisualBasic.ApplicationServices.User.IsAuthenticated" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a value that indicates whether the user has been authenticated.</summary>
<value>
<see langword="True" /> if the user was authenticated; otherwise, <see langword="False" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The `My.User.IsAuthenticated` property allows your code to determine if the current user has been authenticated.
> [!NOTE]
> The exact behavior of `My.User` object depends on the type of the application and on the operating system on which the application runs. For more information, see the <xref:Microsoft.VisualBasic.ApplicationServices.User> class overview.
## Availability by Project Type
|Project type|Available|
|-|-|
|Windows Application|**Yes**|
|Class Library|**Yes**|
|Console Application|**Yes**|
|Windows Control Library|**Yes**|
|Web Control Library|**Yes**|
|Windows Service|**Yes**|
|Web Site|**Yes**|
## Examples
This example verifies that the user has been authenticated before accessing a resource.
[!code-vb[VbVbalrMyUser#2](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrMyUser/VB/Class1.vb#2)]
]]></format>
</remarks>
<permission cref="T:System.Security.Permissions.SecurityPermission">Describes a set of security permissions applied to code. Associated enumeration: <see cref="F:System.Security.Permissions.SecurityPermissionFlag.ControlPrincipal" />.</permission>
</Docs>
</Member>
<Member MemberName="IsInRole">
<MemberSignature Language="C#" Value="public bool IsInRole (Microsoft.VisualBasic.ApplicationServices.BuiltInRole role);" />
<MemberSignature Language="ILAsm" Value=".method public instance bool IsInRole(valuetype Microsoft.VisualBasic.ApplicationServices.BuiltInRole role) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.ApplicationServices.User.IsInRole(Microsoft.VisualBasic.ApplicationServices.BuiltInRole)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="role" Type="Microsoft.VisualBasic.ApplicationServices.BuiltInRole" />
</Parameters>
<Docs>
<param name="role">The built-in Windows role for which to check membership.</param>
<summary>Determines whether the current user belongs to the specified role.</summary>
<returns>
<see langword="True" /> if the current user is a member of the specified role; otherwise, <see langword="False" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The `My.User.IsInRole` method allows your code to determine if the current user is a member of the specified role.
The overload of the `My.User.IsInRole` method that takes a string provides easy access to the <xref:System.Security.Principal.IPrincipal.IsInRole%2A> method of the current principal.
The overload of the `My.User.IsInRole` method that takes a `BuiltInRole` enumeration behaves differently, depending on the current principal. If it is a Windows user principal (<xref:System.Security.Principal.WindowsPrincipal>), this function converts `role` to the equivalent <xref:System.Security.Principal.WindowsBuiltInRole> enumeration and returns the result of calling <xref:System.Security.Principal.WindowsPrincipal.IsInRole%2A>. If the current principal is any other principal, this function passes the name of the enumeration value in `role` to the principal's <xref:System.Security.Principal.IPrincipal.IsInRole%2A> method.
> [!NOTE]
> The exact behavior of the `My.User` object depends on the type of the application and on the operating system on which the application runs. For more information, see the <xref:Microsoft.VisualBasic.ApplicationServices.User> class overview.
## Availability by Project Type
|Project type|Available|
|-|-|
|Windows Application|**Yes**|
|Class Library|**Yes**|
|Console Application|**Yes**|
|Windows Control Library|**Yes**|
|Web Control Library|**Yes**|
|Windows Service|**Yes**|
|Web Site|**Yes**|
## Examples
This example checks if the user is an administrator before accessing a resource.
[!code-vb[VbVbalrMyUser#1](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrMyUser/VB/Class1.vb#1)]
]]></format>
</remarks>
<permission cref="T:System.Security.Permissions.SecurityPermission">Describes a set of security permissions applied to code. Associated enumeration: <see cref="F:System.Security.Permissions.SecurityPermissionFlag.ControlPrincipal" />.</permission>
</Docs>
</Member>
<Member MemberName="IsInRole">
<MemberSignature Language="C#" Value="public bool IsInRole (string role);" />
<MemberSignature Language="ILAsm" Value=".method public instance bool IsInRole(string role) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.VisualBasic.ApplicationServices.User.IsInRole(System.String)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="role" Type="System.String" />
</Parameters>
<Docs>
<param name="role">The name of the role for which to check membership.</param>
<summary>Determines whether the current user belongs to the specified role.</summary>
<returns>
<see langword="True" /> if the current user is a member of the specified role; otherwise, <see langword="False" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The `My.User.IsInRole` method allows your code to determine if the current user is a member of the specified role.
The overload of the `My.User.IsInRole` method that takes a string provides easy access to the <xref:System.Security.Principal.IPrincipal.IsInRole%2A> method of the current principal.
The overload of the `My.User.IsInRole` method that takes a `BuiltInRole` enumeration behaves differently, depending on the current principal. If it is a Windows user principal (<xref:System.Security.Principal.WindowsPrincipal>), this function converts `role` to the equivalent <xref:System.Security.Principal.WindowsBuiltInRole> enumeration and returns the result of calling <xref:System.Security.Principal.WindowsPrincipal.IsInRole%2A>. If the current principal is any other principal, this function passes the name of the enumeration value in `role` to the principal's <xref:System.Security.Principal.IPrincipal.IsInRole%2A> method.
> [!NOTE]
> The exact behavior of the `My.User` object depends on the type of the application and on the operating system on which the application runs. For more information, see the <xref:Microsoft.VisualBasic.ApplicationServices.User> class overview.
## Availability by Project Type
|Project type|Available|
|-|-|
|Windows Application|**Yes**|
|Class Library|**Yes**|
|Console Application|**Yes**|
|Windows Control Library|**Yes**|
|Web Control Library|**Yes**|
|Windows Service|**Yes**|
|Web Site|**Yes**|
## Examples
This example checks if the user is an administrator before accessing a resource.
[!code-vb[VbVbalrMyUser#1](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrMyUser/VB/Class1.vb#1)]
]]></format>
</remarks>
<permission cref="T:System.Security.Permissions.SecurityPermission">Describes a set of security permissions applied to code. Associated enumeration: <see cref="F:System.Security.Permissions.SecurityPermissionFlag.ControlPrincipal" />.</permission>
</Docs>
</Member>
<Member MemberName="Name">
<MemberSignature Language="C#" Value="public string Name { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string Name" />
<MemberSignature Language="DocId" Value="P:Microsoft.VisualBasic.ApplicationServices.User.Name" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.VisualBasic</AssemblyName>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the name of the current user.</summary>
<value>
<see langword="String" />. The name of the current user.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
You can use the `My.User` object to get information about the current user.
The principal that authenticates the user also controls the format of the user name. By default, an application uses Windows authentication, and the user name has the format DOMAIN\USERNAME. A custom implementation of the principal does not necessarily use the same format.
> [!NOTE]
> The `My.User.Name` property returns an empty string when run under Windows 95 and Windows 98 because those operating systems do not recognize user names.
> [!NOTE]
> The exact behavior of the `My.User` object depends on the type of the application and on the operating system on which the application runs. For more information, see the <xref:Microsoft.VisualBasic.ApplicationServices.User> class overview.
## Availability by Project Type
|Project type|Available|
|-|-|
|Windows Application|**Yes**|
|Class Library|**Yes**|
|Console Application|**Yes**|
|Windows Control Library|**Yes**|
|Web Control Library|**Yes**|
|Windows Service|**Yes**|
|Web Site|**Yes**|
## Examples
This example checks if the application is using Windows or custom authentication, and uses that information to parse the `My.User.Name` property.
[!code-vb[VbVbalrMyUser#3](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrMyUser/VB/Class1.vb#3)]
]]></format>
</remarks>
<permission cref="T:System.Security.Permissions.SecurityPermission">Describes a set of security permissions applied to code. Associated enumeration: <see cref="F:System.Security.Permissions.SecurityPermissionFlag.ControlPrincipal" />.</permission>
</Docs>
</Member>
</Members>
</Type>