Solve the problem that the Godaddy host Asp.net cannot upload files

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.