Re: Webpart unable to register as safecontrol

From: MatsonPP (bloody_soul_2_at_hotmail.com)
Date: 03/22/05


Date: 22 Mar 2005 07:51:06 -0800

Here are the steps to registering a webpart as safe for all of you who
have never done it:

1. You must create a key file: either open up visual studios.net's
Command Prompt or do a start->run->"cmd" and then navigate to
"C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin" or if
you have not installed to the default directory, navigate to the
\SDK\v1.1\Bin directory of your Visual Studio Installation.

So, at that prompt type "sn -k [location of key file and name].snk"
(without quotes) and push enter. for example: "sn -k c:\key.snk"

This will create your key. (Don't close the command prompt just yet)

2. Now, open up your webpart in visual studio and in the
AssemblyInfo.cs file, scroll down till you see:
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

Make the AssemblyKeyFile look like [assembly:
AssemblyKeyFile("c:\key.snk")] or whatever location you chose.

NOW REBUILD YOUR ENTIRE SOLUTION.

3. Go back into the command prompt. Do you know where your project's
dll compiled? I hope you do, but if you don't know, go back into visual
studio where your project is open, right click on the project name
located in the Solution Explorer window in the right-hand side of the
screen and select properties. In the Property Pages Window that pops
up, click Configuration Properties. In the right hand side, locate
"outut path". This is the location of your dll.

So go back to the command prompt (you should still be at the same
"C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin"
prompt, and type "sn.exe -T [location of your projects .dll file]"
for example "sn -T C:\myProjects\myProject\bin\Debug\myProject.dll"

This will pop you out a Public Key Token :) Copy this public key token
or write it down or something.

4. Now, open up your .dwp file (should also be showing up in the
solution explorer) and between the assembly tags write this:

<Assembly>ProjectName(Your webpart's Project title), Version=1.0.0.0(or
your dll's version, Culture=neutral(almost always neutral),
PublicKeyToken=(the key token you recieved from step 3)</Assembly>
also:
<TypeName>YourNameSpace.YourClassName</TypeName>

5. So now locate your dwp file which is somewhere in the depths of your
project's folder (shouldn't be hard to find) and your are going to copy
that file to "\\Servername\inetpub\wwwroot\wpcatalog"

6. Now you are going to go into the
"\\Servername\inetpub\wwwroot\web.config" file and add this line just
above </SafeControls>

"<SafeControl Assembly="[Stuff between assembly tags in .dwp file]"
Namespace="MyNameSpace" TypeName="*" />" for example

"<SafeControl Assembly="ProjectName, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=4j4455kl5jdkfh567" Namespace="MyNameSpace" TypeName="*"
/>"

Now file->save web.config

7. Now, copy your project's dll to somewhere on the server. Keep the
window open where you copied it. Open the folder "c:\windows\assebly"
and DRAG your dll in there. A dll can only be dragged into this special
folder it cannot be copied. Don't bother trying to write some little
.bat file to do a quick copy every time you compile because it ain't
gunna work!

8. On the server do a start->run->"iisreset" and everything should be
handy-dandy.

IF SOMETHING DID NOT WORK THEN YOU MUST HAVE MISSPELLED SOMETHING.
Everything in this procedure is CASE-SENSITIVE. I've been burned many a
time with a lowercase letter somewhere when it should be capitol.

If there are any questions, PLEASE type them in and I will answer them.
I will be monitoring this page for a good week or so.

Thanks!
MatsonPP



Relevant Pages

  • Deployment Status
    ... I have multiple customer webspaces on a remote server. ... If Visual Studio ... Version 1.1 would set the name of the DLL to the name of the NameSpace. ...
    (microsoft.public.dotnet.framework.aspnet)
  • CoCreateObject of C# ComVisible object from C++ Crashes
    ... I have three DLL projects, all compiled from Visual Studio 2003 ... setup to get to the point where I try to call CoCreateInstance takes ... the CoCreateInstance call causes Visual Studio to crash ...
    (microsoft.public.dotnet.framework.interop)
  • dll copy question
    ... I have a program that references a DLL. ... Microsoft Visual Studio Tools for Office 77633-163-9000041-41865 ... Microsoft SQL Server Analysis Services Designer ... Microsoft SQL Server Integration Services Designer ...
    (microsoft.public.vsnet.general)
  • Re: Reference DLL with CopyLocal = False problem ....
    ... CopyLocal is just a visual studio directive. ... on a server and I made a Reference to this DLL. ... I check my Reference paths in Project properties - there is a valid path ...
    (microsoft.public.dotnet.general)
  • Visual Studio Hosting Process locks Dependent DLL/PDB
    ... I have a solution consisting of a C# DLL ... Visual Studio hosting process" checked. ... the Visual Studio hosting process starts up in the ...
    (microsoft.public.vstudio.general)

Quantcast