Services and Redirected Drives(服务程序和重定向驱动器)

本文阐述了服务程序不应直接通过映射驱动器盘符访问本地或网络资源,而应使用通用命名规则(UNC)。同时介绍了在不同Windows系统版本中重定向驱动器的工作原理及其限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

INFO: Services and Redirected Drives

服务程序和重定向驱动器

 

SUMMARY

摘要

A service should not directly access local or network resources through mapped drive letters. Additionally, a service should not use the WNetXXXXXXX APIs to add, remove, or query any mapped drive letters. Although the WNetXXXXXXX APIs may return successfully, the results will be incorrect. A service (or any process that is running in a different security context) that must access a remote resource should use the Universal Naming Convention (UNC) name to access the resource. UNC names do not suffer from the limitations described in this article.

服务程序不能直接通过映射驱动器盘符(如:H:)访问本地或网络资源。另外,服务程序也不能使用WNetXXXXXXX APIs添加、移除或查询任何映射驱动器盘符。通过WNetXXXXXXX APIs也许会返回成功,而实际结果却并不正确。服务(或任何运行于不同security上下文的进程)一定要访问远程资源的话,应该使用通用命名规则(UNC, Universal Naming Convention)名称。UNC名不受本文所描述的限制的影响。

 

 

MORE INFORMATION

更多信息

When the system establishes a redirected drive, it is stored on a per-user basis. Only the user himself can manipulate the redirected drive. The system keeps track of redirected drives based on the user's Logon Security Identifier (SID). The Logon SID is a unique identifier for the user's Logon Session. A single user can have multiple, simultaneous logon sessions on the system.

系统建立一个重定向驱动器时,它被存储在per-user basis(不清楚,各用户基本信息表?)。只有用户自身可以操作重定向驱动器。系统通过用户登录安全标识符(SID, Security Identifier)信息,保持对重定向驱动器的追踪。登录SID是用户登录会话的唯一标识符,单个用户在系统中可以有多个并发的登录会话。

 

If a service is configured to run under a user account, the system will always create a new logon session for the user and then launch the service in that new logon session. Thus, the service cannot manipulate the drive mappings that are established within the user's other session(s).

如果服务被注册运行在某个用户账号下,系统将会为该用户创建一个新的登录会话,并在这个新会话中运行此服务。因此,该服务不能操作该用户在其他会话中所建立的驱动器映射。

 

 

Redirected Drives on Microsoft Windows NT and Microsoft Windows 2000

基于Microsoft Windows NT2000系统的重定向驱动器

On Windows NT and on Windows 2000, drive letters are global to the system. All users on the system share the letters A-Z. Each user does not get their own set of drive letters. This means a user can access the redirected drives of another user if they have the appropriate security access.

Windows NTWindows 2000中,驱动器盘符对于系统是全局的,系统的所有用户共享盘符A-Z。每个用户不保有专属于自己的驱动器集合,这意味着如果拥有适当的安全使用权,用户就能够访问另一用户的重定向驱动器。

 

If a user tries to redirect a drive letter that is used by another user (such as WNetAddConnection2()), the error ERROR_ALREADY_ASSIGNED will be returned. Although the redirected drive is global to all users, only the user who established it can manipulate it. Another example is if a user tries to remove or query information on a redirected drive that was established by a different user. The WNetGetConnection() function and the WNetCancelConnection2() function will return the following error message:

ERROR_NOT_CONNECTED

如果用户试图重定向一个已被其他用户所使用的驱动器盘符(WNetAddConnection2()),将返回错误ERROR_ALREADY_ASSIGNED。尽管重定向驱动器对于所有用户是全局的,也只有创建它的用户才能对它进行操作。另一个事例是如果一个用户试图移除或查询一个由另一个用户建立的重定向驱动器时,WNetGetConnection()WNetCancelConnection2()函数将返回错误信息:ERROR_NOT_CONNECTED

 

If a user tries to enumerate the list of redirected drives through WNetOpenEnum() and WNetEnumResource(), the functions only list redirected drives that were established by that user. Drives that were redirected by other users will not be visible.

如果用户试图通过WNetOpenEnum()WNetEnumResource()函数枚举重定向驱动器列表时,只会列出由该用户建立的重定向驱动器,而其他用户所建立的是非可见的。

 

Windows NT File Manager and Windows NT Explorer can see all the redirected drives because they call the GetDriveType() function on each drive, and they display an icon for each drive that is found. Windows NT File Manager and Windows NT Explorer create an icon for redirected drives that are created by all users because drive letters are global to the system. However, the interactive user cannot use Windows NT File Manager or Windows NT Explorer to disconnect the drive because the drive was created in a different logon session.

Windows NT文件管理器和Windows NT Explorer能“看见”所有的重定向驱动器,它们对每个驱动器调用GetDriveType()函数,并显示所有驱动器的图标。Windows NT文件管理器和Windows NT Explorer为所有用户创建的重定向驱动器都生成一个图标,因为驱动器盘符是全局的。但是,交互用户不能使用Windows NT File ManagerWindows NT Explorer重定向驱动器之断开连接,因为这些驱动器是在不同的登录会话中建立的。

 

If a service that is running in the LocalSystem security context establishes a drive mapping, only that service or another process running in the LocalSystem account can call WNetCancelConnection2() to disconnect the drive.

如果一个运行在本地系统security上下文的服务建立一个驱动器映射,只有该服务或者其它运行在本地系统账户下的进程才能通过调用WNetCancelConnection2()切断与该驱动器的连接。

Note All processes that are running in the LocalSystem account are running in the same logon session.

注意:所有运行在本地系统账户下的进程都运行于相同的登录会话中。

 

 

Redirected Drives on Microsoft Windows XP

基于Microsoft Windows XP的重定向驱动器

On Windows XP and on Microsoft Windows Server 2003, each logon session receives its own set of drive letters, A through Z. Therefore, redirected drives cannot be shared between processes that are running under different user accounts. Additionally, a service (or any process that is running in its own logon session) cannot access the drive letters that are established in a different logon session. However, drive letters that are mapped from a service that is running under the local System account are visible to all logon sessions.

Windows XPMicrosoft Windows Server 2003系统中,每个登录会话接收它自己的驱动器盘符集,从AZ。因此,重定向驱动器无法在运行于不同用户帐户中的进程之间共享。另外,一个服务(或任何运行于自身登录会话的进程)不能访问不同登录会话中所建立的驱动器盘符。但是,由运行在本地系统帐户下的服务所映射的驱动器盘符,对于所有登录会话都是可见的。

 

 

MSDN原文地址

http://support.microsoft.com/kb/180362/en-us

重定向系统各临时文件夹到另外盘符 首先要在“开始”——“运行”内输入“regedit”打开注册表编辑器,然后要在“文件”下拉菜单中的“导出”功能备份好注册表,以防万一,接着在左侧窗口依次打开: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders 在右侧窗口里,你看到的“名称”就代表那些特殊的文件夹,“数据”就是它们所对应的默认存储路径。修改默认的路径就可以让你的桌面文件夹移动了,下面是所有的. 下面介绍一下各个“名称”所代表的文件夹 名称 含义 默认路径 AppData 应用程序数据目录 C:\Documents and Settings\User name\Application Data Cookies Cookies路径 C:\Documents and Settings\User name\Cookies Desktop 桌面路径 C:\Documents and Settings\User name\桌面 Favorites 收藏夹 C:\Documents and Settings\User name\Favorites NetHood NetHood路径 C:\Documents and Settings\User name\NetHood Personal 我的文档 C:\Documents and Settings\User name\My Documents PrintHood 打印 C:\Documents and Settings\User name\PrintHood Recent 文档项路径 C:\Documents and Settings\User name\Recent SendTo SendTo路径 C:\Documents and Settings\User name\SendTo Start Menu 开始菜单路径 C:\Documents and Settings\User name\「开始」菜单 Templates 新建文件目录 C:\Documents and Settings\User name\Templates Programs 程序菜单路径 C:\Documents and Settings\User name\「开始」菜单\程序 Startup 启动路径 C:\Documents and Settings\User name\「开始」菜单\程序\启动 History 网页历史记录 C:\Documents and Settings\ User name \Local Settings\History My Pictures 图片收藏 C:\Documents and Settings\User name\My Documents\My Pictures My Music 我的音乐 C:\Documents and Settings\User name\My Documents\My Music My Video 我的视频 C:\Documents and Settings\User name\My Documents\My Videos Cache Internet临时文件夹 C:\ Documents and Settings\User name \Temporary Internet Files 这些文件夹称为Shell文件夹 其中“User name”为当前用户的名称 了解了对应的文件夹,就可以根据自己的需要去更改对应的路径了。(千万不要在这儿改啊,那样可就瞎忙乎了,系统重起后它会恢复成原来的路径) 在同一层中你可以看到一个“User Shell Folders”的子键,即在HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ User Shell Folders 这里包括了用户定制的所有Shell文件夹的值项。只要通过修改“数据”,就可以改变它们的存储路径。双击需要修改的名称,在弹出的“编辑字符串”的“数值数据”里填上你要更改的完整路径,按下“确定”就完成了。如果没有你需要的,可以在右边窗口单击鼠标右键,选择“新建”菜单中的“字符串值”命令,对应上表,添加一个用于Shell文件夹的字符串值。 在上面的文件夹中,并没有outlook的通讯簿邮件存放路径,它们分别在 通讯簿路径: HKEY_CURRENT_USER\Software\Microsoft\WAB\WAB4\Wab File Name主键下,将
<think>好的,我需要帮助用户解决前端表单上传后如何实现页面重定向的问题。首先,我应该回顾用户提供的引用内容,特别是关于重定向的部分。引用[1]提到使用AJAX处理响应后通过JavaScript进行location.href跳转,而引用[2]展示了后端使用Gin框架进行重定向的例子。引用[3]则详细说明了HTTP重定向的状态码,比如302、303307的区别,这对选择正确的状态码很重要。 用户的问题是前端表单上传后的重定向,所以需要从前端后端两方面考虑。传统的表单提交会触发页面跳转,如果后端返回重定向响应,浏览器会自动处理。但如果是使用AJAX提交表单,可能需要手动处理重定向,如引用[1]所述。此外,引用[3]中的303状态码适用于POST后的重定向,避免重复提交,这可能是一个关键点。 接下来,我需要整理实现方法。首先,传统表单提交的方式,后端返回3xx状态码Location头,前端自动跳转。其次,使用AJAX时,需要在成功回调中通过JavaScript跳转。还要注意表单的target属性,如果设置为隐藏的iframe,可以在不离开当前页面的情况下处理响应,但可能需要配合后端重定向。 另外,需要提到HTTP状态码的选择,比如303适用于POST后的重定向,确保使用GET方法,避免重复提交。还要考虑表单的enctype属性是否正确设置为multipart/form-data,特别是文件上传时。 可能的相关问题包括如何处理AJAX重定向、不同状态码的区别、如何防止重复提交等。需要确保回答结构清晰,步骤明确,同时引用提供的资料来支持建议。</think>### 前端表单上传后重定向的实现方法 #### 1. **传统表单提交(非AJAX)** 若直接使用表单提交(未使用AJAX),后端返回**HTTP重定向状态码(如302/303)** 并设置`Location`响应头,浏览器会自动跳转。 **实现步骤:** - 前端表单设置`action``method`,例如: ```html <form action="/upload" method="post" enctype="multipart/form-data"> <input type="file" name="file"> <button type="submit">提交</button> </form> ``` - 后端处理上传后,返回重定向响应: ```javascript // Node.js示例(Express框架) app.post('/upload', (req, res) => { // 处理文件上传逻辑 res.redirect(303, '/success-page'); // 使用303状态码避免重复提交[^3] }); ``` 此时浏览器会自动跳转到`/success-page`。 --- #### 2. **AJAX表单提交 + 前端手动跳转** 若使用AJAX异步提交表单,需在前端手动处理重定向。 **实现步骤:** - 前端通过`fetch`或`XMLHttpRequest`发送请求: ```javascript document.querySelector('form').addEventListener('submit', async (e) => { e.preventDefault(); const formData = new FormData(e.target); const response = await fetch('/upload', { method: 'POST', body: formData }); if (response.redirected) { // 检查是否被重定向 window.location.href = response.url; // 手动跳转[^1] } }); ``` - 后端仍需返回重定向响应(如302或303),前端通过`response.redirected`判断并跳转。 --- #### 3. **使用隐藏iframe实现无刷新重定向** 通过设置表单的`target`属性为隐藏的`<iframe>`,让响应在iframe中处理,再通过JavaScript读取重定向指令: ```html <form action="/upload" method="post" enctype="multipart/form-data" target="hidden-iframe"> <input type="file" name="file"> <button type="submit">提交</button> </form> <iframe name="hidden-iframe" style="display:none;"></iframe> <script> document.querySelector('iframe').addEventListener('load', function() { const iframeLocation = this.contentWindow.location.href; if (iframeLocation.includes('/success-page')) { window.location.href = iframeLocation; // 主页面跳转 } }); </script> ``` 后端仍需返回重定向响应。 --- #### **关键注意事项** - **状态码选择**: - 使用`303 See Other`(POST后重定向到GET请求)可避免表单重复提交。 - `302 Found`可能导致旧浏览器保留POST方法,引发安全问题。 - **跨域限制**:若重定向到不同域名,需确保目标地址允许跨域访问(CORS配置)。 - **表单编码**:上传文件时需设置`enctype="multipart/form-data"`。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值