2

我创建了一个有两个模块的网站,

  1. 行政
  2. 用户

它们托管在不同的域上。现在,当用户打开其域时,假设它的abc.com可以注册他们的公司并从那里上传照片,上传的照片将进入Company_Logo FOLDER。现在假设 ADMIN 的域是xyz.com。现在我希望管理员打开它的 xyz.com 并可以看到从 abc.com 上传的照片现在我想像管理员一样从 xyz.com 可以将上传的照片更改为位于 Company_Logo 文件夹中的 abc.com。

简而言之,照片是从 abc.com 上的用户端上传的,并从 xyz.com 上的 ADMIN 端替换,所以我该怎么做

4

4 回答 4

1

因此,您有两个不同的站点,托管在不同的域甚至不同的服务器上,并且您希望站点 A 在某些文件已上传时通知站点 B。然后,您希望能够从站点 B 更改站点 A 上的该文件。

在我看来,您需要在站点 A 上创建某种 API,让站点 B 的用户(管理员)检查最近上传的文件,并让他们覆盖它。

于 2012-10-04T12:08:16.800 回答
1

好的,这可以完成,但您需要使用HttpHandler. 你可以在这里找到一个很好的例子,但我会详细说明重要的部分。我不能在这里为您编写整个处理程序。

首先,让我们在 web 项目中构建一个类并调用它ImageHandler...

public class ImageHandler : IHttpHandler
{
}

...接下来让我们实现接口...

public bool IsReusable
{
    get { return false; }
}

public void ProcessRequest(HttpContext context)
{
    // find out what we're trying to do first
    string method = context.Request.HttpMethod;

    switch (method)
    {
        case "GET":
            // read the query string for the document name or ID

            // read the file in from the shared folder

            // write those bytes to the response, ensuring to set the Reponse.ContentType
            // and also remember to issue Reponse.Clear()

            break;
        case "PUT":
            // read the Headers from the Request to get the byte[] of the file to CREATE

            // write those bytes to disk

            // construct a 200 response

            break;
        case "POST":
            // read the Headers from the Request to get the byte[] of the file to UPDATE

            // write those bytes to disk

            // construct a 200 response

            break;
        case "DELETE":
            // read the Headers from the Request to get the byte[] of the file to DELETE

            // write those bytes to disk

            // construct a 200 response

            break;
    }
}

...最后我们需要在web.config...中设置处理程序

<configuration>
   <system.web>
      <httpHandlers>
         <!-- remember that you need to replace the {YourNamespace} with your fully qualified -->
         <!-- namespace and you need to replace {YourAssemblyName} with your assembly name    -->
         <!-- EXCLUDING the .dll                                                              -->
         <add verb="*" path="*/images/*" type="{YourNamespace}.ImageHandler, {YourAssemblyName}" />
      </httpHandlers>
   </system.web>
</configuration>

最后,您还要做的事情是传递某种会话密钥,当您进入处理程序时可以验证该会话密钥,否则这对所有人都是开放的。如果你不需要PUT,POSTDELETE动词也没关系,但你需要。

GET从技术上讲,如果您不关心每个人都可以访问,则不需要检查会话密钥GET,但您必须检查其他人。

于 2012-10-04T12:19:05.790 回答
1

你有两个选择。

  • 如果您的两个站点都托管在同一台计算机或共享托管环境中,则您的站点很可能可以访问其他目录。在这种情况下,您将可以轻松地将图像放置在所需的文件夹中。

  • 现在是第二种情况,您的一个站点无权访问另一个站点的文件夹,这相当复杂。您必须创建一个代理,管理站点将在其中接受图像,然后将其放入主站点文件夹中。我不推荐这个。

于 2012-10-04T11:58:10.420 回答
0

您可以通过 2 个步骤执行此操作:

1) 使用标准文件上传机制将图像上传到您的服务器

2)使用HttpWebRequest类在原始上传后立即将图像上传到服务器端的不同服务器。请参考这篇文章:使用 HTTPWebrequest (multipart/form-data) 上传文件

请参阅此参考: http ://forums.asp.net/t/1726911.aspx/1

于 2012-10-04T12:13:23.497 回答