Microsoft Knowledge Base Email Alertz

KBAlertz.com: Adding Codegroup for a control hosted on website to .Net Runtime Policy

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 2.0 Web Hosting with SQL 2005: Click Here!
Discount ASP.NET Hosting


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Adding Codegroup for a control hosted on website to .Net Runtime Policy

Article ID:948447
Last Review:January 29, 2008
Revision:1.2
Source: Microsoft Support

Back to the top

RAPID PUBLISHING

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

Back to the top

Action



When a web application that has a control embedded in it; in order to instantiate the control the .Net Runtime Security needs to be configured on the client machine to allow fulltrust for the control to be loaded.  One method to achieve this is to re-direct the client to a page that has a link to download a .vbs file locally that will execute on the client machine and make this configuration change without having the user interact with the .Net Framework Configuration tool. The execution sets up a code group for the control (with a membership condition : Site, permission set : Full Trust and the site name corresponding to the server where the .vbs file was downloaded from) and then adds the codegroup to the security policy.

Back to the top

Result

In Windows XP environment - the downloaded .vbs file can be executed which sets runtime security settings correctly without user interaction.

But In Windows Vista - the .vbs file will NOT execute - even if the user logged in is part of the administrators group. One work around is  to :
1.  Save the file locally ,
2.  Execute the vbs file  in command line which is opened to run as administrator . 
3.  This is be design of Vista security where any system changes need to be explicitly run as administrator.







Back to the top

Cause



The reason the control cannot instantiate is because .Net security policy prevents code downloaded from the Internet from running with fulltrust.  The user must enable the code to run on the local machine via the caspol.exe command line or the .Net Framework configuration wizard.  The vbs script is used to minimized user interaction.

In order to run caspol on Vista machine the script needs to run in an administrator command prompt.  This is a security feature in Vista so the script needs to run with explicit elevated administrator trust.

    

Back to the top

Resolution



The script below shows how such a vbs file should look like and also how the verb "runas" can be passed to either the ShellExecute API or to its COM equivalent, the ShellExecute method of Shell.Application, will prompt for elevation for administrator login to enable elevated trust for the script to run.

Follow the instructions given below: 
1.Create a new .vbs file using a text editor.
2.Copy the following sample code. 
  
  Set obj = CreateObject("Shell.Application")
  strCasPolExe = objShell.ExpandEnvironmentStrings("%windir%\Microsoft.NET\Framework\v" + strVer + "\caspol.exe")
  strCommandLine =  <"command to be passed to run ">
  obj.ShellExecute strCasPolExe, strCommandLine, "", "runas", 0


















3.Save the .vbs file.
4.Double Click the .vbs file to run it. 

This will run the CASPOL with administrative privilege.

Back to the top

More Information

There is one other way to  configure .net runtime policy on clients machine, by  creating an msi and adding custom action to it using Orca tool.

How to create a Windows Installer package that uses the Code Access Security Policy tool in Visual Studio 2005
http://kbalertz.com/Feedback.aspx?kbNumber=931867 (http://kbalertz.com/Feedback.aspx?kbNumber=931867)

More info on Code Access Security
http://msdn2.microsoft.com/en-us/library/930b76w0(VS.71).aspx (http://msdn2.microsoft.com/en-us/library/930b76w0(VS.71).aspx)

Back to the top

DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.

Back to the top


APPLIES TO
•Microsoft .NET Framework 3.0
•Microsoft .NET Framework 2.0 Software Development Kit
•Microsoft .NET Framework 2.0
•Microsoft .NET Framework 3.5
•Microsoft .NET Framework 1.1 Service Pack 1
•Microsoft .NET Framework 1.1

Back to the top

Keywords: 
kbnomt kbrapidpub KB948447

Back to the top

       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please