在配置IIS负载均衡时,引起的一系列问题

问题一:

IIS中要上传文件的路径是另一台服务器的地址(如:本机IP是192.168.0.100,文件保存的路径在://192.168.0.101/images/folder),在上传时抛出异常:

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

解决的办法:在webconfig中增加配置节点:

<identity impersonate="true" userName="administrator" password="P1234!@#$" />

问题二:

在打开(或下载)文件(writeFile)时,又一直提示上面的那个异常错误。

一直在权限的道路上折腾、摸索、修改。直到最后才怀疑是不是代码有问题,现在贴出修改后的完整代码:

Response.Clear();

// 必须有这一行才能打开,否则会弹出下载保存确认框

Response.AddHeader("Content-Disposition", "inline;filename=" + Server.UrlEncode(fi.FullName));

Response.AddHeader("Content-Length", fi.Length.ToString());  // 可有可无

Response.ContentType = "application/octet-stream;charset=gb2321";  // 可有可无

Response.WriteFile(fi.FullName);

Response.Flush(); // 必须有这一行

Response.Close();

高亮的那几行代码非常重要,其中Content-Disposition也起了决定性作用,Content-Disposition的两个值代表的含义:

////attachment --- 作为附件下载

////inline --- 在线打开

附上源码:

 1         protected void btnReadFile_Click(object sender, EventArgs e)
 2         {
 3             string path = Path.Combine(this.txtFolderPath.Text, this.txtFilePath.Text);
 4             FileInfo fi = new FileInfo(path);
 5             if (fi.Exists)
 6             {
 7                 //Response.Clear();
 8                 Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(fi.Name));
 9                 //Response.AddHeader("Content-Length", fi.Length.ToString());
10                 //Response.ContentType = "application/octet-stream;charset=gb2321";
11                 Response.WriteFile(fi.FullName);
12                 Response.Flush();
13                 Response.End();
14 
15                 labResult2.Text = "OK!";
16             }
17             else
18             {
19                 labResult2.Text = "Error.File not Exists!";  
20             }
21         }
下载文件代码

其他下载文件的几个函数,则大同小异,网上资料很多。

问题三:

重写URL在线下没有问题,部署到IIS中却出现404的问题

IIS     在网上百度无数次,在google翻墙无数次,去配置应用程序映射(仍然没有解决问题),去配置日志跟踪(仍然没有解决问题),甚至重新安装了IIS某些配置。最后非常仔细的对比两个服务器(一个服务器没有问题,一个服务器有问题)的应用程序池配置,shit!发现“启用32位应用程序”一个是“true”,一个是“false”,操,改成true之后,终于不再抛出404了。

问题四:

将“启用32位应用程序”改成“True”后,oracle会连接不上,然后又从线下32位的机器上拷了一个oracle_DataAccess.dll上去,结果又抛出下面这个异常:

The provider is not compatible with the version of Oracle client

很明显的,提示oracle_DataAccess版本不一致。后来查了资料(主要是查的如何启用32位应用程序又能使用64位的oracle数据库)还是无果。最后想到帮我解决了问题三的那一台服务器,从里面的一个站点把oracle相关的dll全部拷过来(先把出问题的那个服务器站点的oracle相关的dll全部删除)后,成功了!!!

原文地址:https://www.cnblogs.com/Denny_Yang/p/4387162.html