| |

VerySource

 Forgot password?
 Register
Search
View: 1151|Reply: 8

asp.net dynamically create virtual directory problem

[Copy link]

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-10-17 12:30:01
| Show all posts |Read mode
As mentioned above, a lot of codes on the Internet can be realized under the winform program, but cannot be realized under asp.net. Unknown errors are always reported. Searching a lot of code is not working. Please be a successful master guiding mystery.
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-10-17 12:45:01
| Show all posts
1. Add System.DirectoryServices
2.using System.DirectoryServices;
3. In the code event as follows:
   protected void BT_submit_Click(object sender,EventArgs e)
    {
        string _server = "localhost";
        string _website = "1";
        string strPath = "IIS://" + _server + "/W3SVC/" + _website +"/ROOT";

        dirroot = new DirectoryEntry(strPath);
        DirectoryEntry newVirDir = dirroot.Children.Add("MyNewSite3", "IIsWebVirtualDir");
        Response.Write(dirroot.Name);
        newVirDir.Invoke("AppCreate", true);
        newVirDir.CommitChanges();
        dirroot.CommitChanges();
        Response.Write(newVirDir.Name+"Created successfully"+newVirDir.Path);
    }
Reply

Use magic Report

0

Threads

13

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-10-17 13:00:01
| Show all posts
I implemented this a few years ago (the project required it, but it was no longer needed, so I don’t know where the code was lost:)). The principle is no different from winform. The key is that the asp.net application is executed by the user aspnet. It does not have sufficient authority to operate IIS, so you need to simulate an administrator account to have the authority to implement this function. For simulation, please see this: http://support.microsoft.com/kb/306158/zh-cn
Reply

Use magic Report

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-10-17 13:30:02
| Show all posts
Thank you everyone, except for theiceice930Xiongtai method, I have tried everything, but it still doesn't work.
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-10-17 14:00:01
| Show all posts
You have to come up with your error message. You can use it once you get it. Diao, debug it by yourself. I have never seen such a lazy person.
Reply

Use magic Report

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-10-17 14:15:01
| Show all posts
Unknown error (0x80005000)
Explanation: During the execution of the current web request, an unhandled exception occurred. Please check the stack trace for details about the error and the source of the error in the code.

Exception details: System.Runtime.InteropServices.COMException: Unknown error (0x80005000)

Source error:


Line 165:
Line 166: DirectoryEntry root = new DirectoryEntry(strWeb);
Line 167: foreach(DirectoryEntry oEntry in root.Children)
Line 168: {
Line 169: if(oEntry.SchemaClassName == strSchema)
Reply

Use magic Report

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-10-17 14:30:01
| Show all posts
I have debugged it N times, it is definitely not a permission issue. I gave the maximum permissions.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-10-17 22:00:01
| Show all posts
There are two methods:
1, FSO
        Dim fso As New Scripting.FileSystemObject
        fso.CreateFolder(Server.MapPath(".")&"\user_info\"&Trim(tmpUsername))
        fso = Nothing

2. IO.Directory.CreateDirectory
        system.IO.Directory.CreateDirectory(Server.MapPath(".")&"\user_info\"&Trim(tmpUsername))

The second method requires setting permissions,
For example, if you want to create a directory on the D drive, right-click on the D drive and add the ASPNET user group to the read and write permissions. Remember, it can only be set in the root directory of the disk.
Reply

Use magic Report

0

Threads

13

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-10-17 22:15:01
| Show all posts
I don't know how the host has set the maximum authority? I have seen many such problems, just simulate it
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list