Godaddy's Windows host, Asp.net's trust mode is medium. If it is a file operation on the new station's sub-station, there will be an error of being unable to call the assembly! I believe many of my friends have tried many ways, but the results are very disappointing. Godaddy is not allowed on the web. modify the trust mode in config. Some friends set the version of Asp.net to 1.1, so that they can use the full trust mode. What should we do if our program is. net2.0 or even. Net 4.0?
The following example illustrates how to solve the problem of the goddady host having no permission to call the assembly!
If you upload a file on the sub-site, you are prompted that you do not have the I/O operation permission, for example:
The allowpartiallytrustedcallersattribute feature allows partially trusted code to call an assembly, which is located in the system. Security namespace.
It can only be used for an assembly. As long as we add this feature to the Assembly, our code can call the system. Security. permissions. fileiopermission assembly.
The Code is as follows:
Using system. reflection;
Using system. Security;
Using system. runtime. compilerservices;
Using system. runtime. interopservices;
// For general information about the assembly, use the following attribute set
// Control. You can modify these attribute values.
// Information associated with the Assembly.
[Assembly: allowpartiallytrustedcallers]
[Assembly: assemblycompany ("opsoft Inc.")]
[Assembly: assemblyproduct ("opsite. Web")]
[Assembly: assemblycopyright ("Copyright (c) www. Ops. CC 2011")]
We need to add the bold part to our Assembly information file. Now we can try the upload function again to find the storage file:
Server. mappath ("~ ") The returned path is already the root directory, so the sub-station file upload to the root directory certainly does not have this permission!
You can use appdomain. currentdomain. basedirectory to obtain the directory path of the current Assembly.
In this way, Asp.net can upload files and I/O operations perfectly in the goddady sub-station!
This article is written by Liu Ming (webmaster of Obo network). repost the article at the original address.