javascript - 通过 iis 在共享文件夹中搜索
问题描述
我编写了一个网络应用程序,用户可以在其中在共享文件夹中搜索文件,然后他们选择的文件将显示在浏览器中。
当我通过 Visual Studio 运行应用程序时,一切正常。
但是,如果我尝试通过 IIS 运行它,当共享文件夹中的 JSON 执行时,我会收到错误 500(内部服务器错误)。
有权限限制吗?我会通过它使用我的凭据的 VS 运行它,而不是在我通过 IIS 运行它时运行它吗?也许共享文件夹必须具有 IIS_IUSR 组的读取权限?我说对了吗?
public JsonResult GetFiles(string MCodeID)
{
if (MCodeID == null)
{
throw new ArgumentNullException(nameof(MCodeID));
}
List<Files> filelist = new List<Files>();
//Searching Files in //192.168.1.191
string path = @"\\192.168.1.191\Materials Project\";
string searchPattern = MCodeID + "*";
DirectoryInfo fi = new DirectoryInfo(path);
if (fi.GetFiles(searchPattern, SearchOption.AllDirectories).Any())
{
foreach (var file in fi.GetFiles(searchPattern, SearchOption.AllDirectories))
{
var changeSlash = file.FullName.Replace('\\', '/');
var filepath = changeSlash.Replace("//192.168.1.191/Materials Project", "");
filelist.Add(new Files
{
FCodeID = filepath,
FDescr = file.Name + " - " + Math.Round((Convert.ToDouble(file.Length) / (1024*1024)), 2) + " MB",
FSize = Math.Round((Convert.ToDouble(file.Length) / (1024 * 1024)), 2)
});
}
filelist.Insert(0, new Files { FCodeID = "0", FDescr = "--Select File--" });
return Json(new SelectList(filelist, "FCodeID", "FDescr"));
}
else
{
filelist.Insert(0, new Files { FCodeID = "0", FDescr = "--No File--" });
return Json(new SelectList(filelist, "FCodeID", "FDescr"));
}
}
<script type="text/javascript">
$(document).ready(function () {
$("#MCodeID").on("change", function () {
var url = '@Url.Content("~/")' + "Materials/GetFiles";
var ddlsource = "#MCodeID";
var items = "<option value='0'>--Select File--</option>";
$("#FCodeID").html(items);
var items = " ";
$("#pdfviewer").hide();
$(".loading-eclipse").show();
$.getJSON(url, { MCodeID: $(ddlsource).val() }, function (data) {
$("#FCodeID").empty();
$.each(data, function (i, file) {
if (file.value.includes("in Use"))
items += "<option value='" + file.value + "'" + "style='background-color:orange;'>" + file.text + "</option>";
else
items += "<option value='" + file.value + "'>" + file.text;
});
$("#FCodeID").html(items);
$(".loading-eclipse").hide();
$("#FCodeID").show();
});
})
})
</script>
当应用程序通过 IIS 执行时,有什么方法可以使用用户凭据?
解决方案
我通过为用户提供对共享文件夹的完全访问权限而不仅仅是读取权限来解决上述错误。感谢@Jalpa 的帮助。
推荐阅读
- reactjs - 使用存储作为跨兄弟姐妹、孩子等的单一数据源的正确方法
- clickhouse - clickhouse:如何避免 DB::Exception:除以零
- sql - 如何检查 SQL 自定义函数返回的结果中是否存在 id(返回 SETOF 表)
- ios - 如何将 Codable 编码与对象内的对象一起使用
- react-native - react native android中navigation.goBack和navigation.dispatch(e.data.action)有什么区别
- reactjs - 我在总和上加一个总和的数学函数不起作用。我收到错误消息“未定义总和”
- c - C LinkedList 指针不适用于动态分配的数组
- swift - 如何扩展二维数组?
- java - 如何更改硒列表中的值
- android - 如何修复 kotlin 语言中的 PARSE_FAILED_MANIFEST_MALFORMED 错误?