简体   繁体   English

使用 MVC IIS 8 错误插入文件夹 C# 发生未处理的访问异常

[英]Insert Folder C# with MVC IIS 8 Error An unhandled access exception has occurred

I Debugging with locally on Windows 10 Pro, VS 2019. This will run just fine on my local machine, but not on the web server my Server is Windows Server 2012 R2 with IIS 8. Does anyone have any ideas as to what the problem might be? I Debugging with locally on Windows 10 Pro, VS 2019. This will run just fine on my local machine, but not on the web server my Server is Windows Server 2012 R2 with IIS 8. Does anyone have any ideas as to what the problem might是?

Here My Code:这是我的代码:

View看法

$.ajax({
                        url: 'AddFolder',
                        type: 'post',
                        data: JSON.stringify(dto),
                        dataType: 'json',
                        contentType: 'application/json;charset=utf-8',
                        success: function (data) {
                            alert("Insert Folder Success");
                            $('#foldername').val("");
                        },
                        error: function (ex) {
                            alert(JSON.stringify(ex));
                        }
                    });

Controller Controller

 public ActionResult AddFolder(videopath model)
        {
            string conSQL = mySetting.ConnectionString;
            SqlDataAdapter dataAdapt = new SqlDataAdapter();
            SqlConnection conn = new SqlConnection(conSQL);
            List<string> ModelData = new List<string>();
            string result;

            try
            {

                string path1 =@"\\kalbox\Video\";
                string path2 = Path.Combine(path1, model.FolderName);
                if (!Directory.Exists(path2))
                {
                    Directory.CreateDirectory(path2);
                    using (SqlCommand command = new SqlCommand("InsertFolderPath", conn))
                    {
                        conn.Open();
                        command.CommandType = CommandType.StoredProcedure;

                        command.Parameters.Add("@FolderName", System.Data.SqlDbType.VarChar);
                        command.Parameters["@FolderName"].Value = model.FolderName;
                        command.Parameters.Add("@FolderPath", System.Data.SqlDbType.VarChar);
                        command.Parameters["@FolderPath"].Value = path2;


                        result = (string)command.ExecuteScalar();
                        ModelData.Add(result);
                        conn.Close();

                    }
                }
                else
                {
                    Console.WriteLine("Folder Exists");
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Json(ModelData, JsonRequestBehavior.AllowGet);
        }

Here my Error:这是我的错误:

  • ASP.NET web page output: Access to the path '\\kalbox\Video\1231' is denied ASP.NET web 页面 output:访问路径 '\\kalbox\Video\1231' 被拒绝

  • Application Event Log:应用程序事件日志:

    Event code: 4011 
    Event message: An unhandled access exception has occurred. 
    Event time: 4/15/2021 4:41:57 PM 
    Event time (UTC): 4/15/2021 9:41:57 AM 
    Event ID: 0c49e37dc23b486b8537561bbc024a5b 
    Event sequence: 7 
    Event occurrence: 1 
    Event detail code: 0 
     
    Application information: 
        Application domain: /LM/W3SVC/1/ROOT/Video_OPL-66-132629533163447222 
        Trust level: Full 
        Application Virtual Path: /Video_OPL 
        Application Path: D:\Video_Training\ 
        Machine name: SERVERNAME
     
    Process information: 
        Process ID: 12844 
        Process name: w3wp.exe 
        Account name: NT AUTHORITY\NETWORK SERVICE 
     
    Request information: 
        Request URL: http:********
        Request path: /Video_OPL/Home/AddFolder 
        User host address: ****** 
        User: domain\Agus.Suhardi 
        Is authenticated: True 
        Authentication Type: Negotiate 
        Thread account name: NT AUTHORITY\NETWORK SERVICE 

  • F12 Console Browser Google Chrome: Failed to load resource: the server responded with a status of 500 (Internal Server Error) F12 控制台浏览器谷歌浏览器:加载资源失败:服务器响应状态为 500(内部服务器错误)

i already find my Windows authentication, and message box show my name ( domainAgus.Suhardi , no slash like domain\Agus.Suhardi )我已经找到我的 Windows 身份验证,并且消息框显示我的名字( domainAgus.Suhardi ,没有像domain\Agus.Suhardi这样的斜线)

var winlogon = '@HttpContext.Current.User.Identity.Name';
alert (winlogon);

Here my Permission Kalbox Folder这是我的许可 Kalbox 文件夹

FYI folder kalbox only add user AD (Active Directory) and My IIS Username is FYI 文件夹 kalbox 仅添加用户 AD(Active Directory)和我的 IIS 用户名是

NT AUTHORITY\NETWORK SERVICE NT AUTHORITY\网络服务在此处输入图像描述

This error may cause by your asp.net account {MACHINE}\ASPNET does not have write access to the path '\kalbox\Video\1231'.此错误可能是由您的 asp.net 帐户 {MACHINE}\ASPNET 没有对路径“\kalbox\Video\1231”的写入权限引起的。

You can try below steps to solve this question:您可以尝试以下步骤来解决此问题:

Right click on folder Properties > Security Tab > Edit > Add > locations > choose your local machine > click OK > Type ASPNET below "Enter the object name to select" > Click Check Names Check the boxes for the desired access (Full Control).右键单击文件夹属性 > 安全选项卡 > 编辑 > 添加 > 位置 > 选择您的本地计算机 > 单击确定 > 在“输入 object 名称以选择”下方键入 ASPNET > 单击检查名称 选中所需访问权限的框(完全控制)。 If it will not work for you do the same with Network Service.如果它对您不起作用,请对网络服务执行相同操作。

Now this should show your local {MACHINENAME}\ASPNET account, then you set the write permission to this account.现在这应该会显示您的本地 {MACHINENAME}\ASPNET 帐户,然后您将写入权限设置为该帐户。

Otherwise if the application is impersonating via, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.否则,如果应用程序正在模拟 via,则身份将是匿名用户(通常是 IUSR_MACHINENAME)或经过身份验证的请求用户。

I already Solve for my case you can try add user Everyone and give Full control我已经解决了我的情况,您可以尝试添加用户Everyone 并给予完全控制

btw tq Samwu for your answer and you are right my account IIS does not have write access顺便说一句 tq Samwu 回答你,你是对的我的帐户 IIS 没有写权限

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发生异常:错误:ENOENT:没有这样的文件或目录 - Exception has occurred: Error: ENOENT: no such file or directory c# WPF 带 Highchart 的 Webbrowser,来自外部源的 Javascript 不工作“此页面上的脚本中发生错误” - c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page" 处理请求时发生未处理的异常 - An unhandled exception occurred while processing the request 运行 ng serve 发生未处理的异常 - Unhandled exception occurred running ng serve 如何解决 angular 错误“发生未处理的异常:找不到模块'typescript'”? - How to solve angular error "An unhandled exception occurred: Cannot find module 'typescript' "? NextJS - 应用程序错误:发生客户端异常 - NextJS - Application Error: A client side exception has occurred 发生未处理的异常:使用 angular 9 在构建产品上超出调用重试次数 - An unhandled exception occurred: Call retries were exceeded on build prod with angular 9 MVC中的用户代码未对HTTP异常进行处理 - HTTP Exception was unhandled by user code in MVC ASP MVC 4中skelJs中的javascript未处理异常 - javascript unhandled exception in skelJs in ASP MVC 4 获取“在执行当前Web请求期间生成了未处理的异常。” 我的MVC UserManagementController中的错误 - Getting 'An unhandled exception was generated during the execution of the current web request.' Error in my MVC UserManagementController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM