【问题标题】:Problems with Asp.net Mvc 2.0 Web.config.debug/release....System.UnauthorizedAccessException was unhandled by user codeAsp.net Mvc 2.0 Web.config.debug/release 的问题....System.UnauthorizedAccessException 未被用户代码处理
【发布时间】:2010-06-22 22:18:45
【问题描述】:

我正在尝试使用 webconfig 的调试和发布版本,但它永远无法正常工作。我正在尝试为我正在使用的名为 combres 的第 3 方库执行此操作。

http://combres.codeplex.com/

所以我首先将所有需要的 web.config 代码放在 web.config 中。现在我有 2 个不同的 .xml 文件(那是你放置 javascript 和 css 路径的地方)。

因此生产将具有不同的 .xml 路径,因此将进行调试。

所以我把这一行移到了web.config的release和debug中,改了xml文件的路径。

    // release webconfig
    <combres definitionUrl="~/App_Data/Combres.xml" />

   // debug webconfig
   <combres definitionUrl="~/App_Data/CombresDevelopment.xml" />

我明白了

System.UnauthorizedAccessException was unhandled by user code
  Message=Access to the path 'E: test.com' is denied.
  Source=mscorlib
  StackTrace:
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
       at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
       at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
       at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
       at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
       at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
       at System.Xml.Linq.XDocument.Load(String uri)
       at Combres.ConfigReader.ReadCombresUrl(String filePath)
       at Combres.Configuration.GetCombresUrl()
       at Combres.WebExtensions.AddCombresRoute(RouteCollection routes, String name)
       at MyApp.MvcApplication.RegisterRoutes(RouteCollection routes) in E:\Global.asax.cs:line 19
       at MyApp3.MvcApplication.Application_Start() in E:\Global.asax.cs:line 46
  InnerException: 

第 19 行 -> routes.AddCombresRoute("Combres");

第 46 行 -> RegisterRoutes(RouteTable.Routes);

所以我不明白为什么会出现此错误。我认为 webconfig jsut 是动态合并的,那么为什么它会在顶层运行,而不是 .debug 呢。

编辑

这是我的文件(出于安全考虑,删除了一些信息)

Web.config

    <configSections>
        <section name="combres" type="Combres.ConfigSectionSetting, Combres, Version=2.0.0.0, Culture=neutral, PublicKeyToken=49212d24adfbe4b4"/>
        <sectionGroup name="elmah">
            <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
            <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
            <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
            <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
            <section name="errorTweet" requirePermission="false" type="Elmah.ErrorTweetSectionHandler, Elmah"/>
        </sectionGroup>
    </configSections>

    <appSettings>....</appSettings>


    <!--<combres definitionUrl="~/App_Data/Combres.xml" />-->
    <!--<combres definitionUrl="~/App_Data/CombresDevelopment.xml" />-->

    <connectionStrings>....</connectionStrings>



    <elmah>
        <errorLog type="Elmah.SqlErrorLog, Elmah" logPath="~/App_Data" connectionStringName="...." />
        <errorFilter>
            <test>
                <equal binding="HttpStatusCode" value="404" type="Int32" />
            </test>
        </errorFilter>
        <security allowRemoteAccess="0" />
    </elmah>

    <system.web>
    <globalization culture="en" uiCulture="en-US" />
    <httpRuntime requestValidationMode="2.0"/>

    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

    <authentication mode="Forms">
    </authentication>

    <pages>
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="CustomHtmlHelpers" />
        <add namespace="Combres.Mvc" />
      </namespaces>
    </pages>

      <httpHandlers>
          <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
      </httpHandlers>

      <httpModules>
          <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
          <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
      </httpModules>

  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

正如你现在看到的,我的梳子被注释掉了,因为现在我必须手动来回切换。

这是我的 web.debug.config

<?xml version="1.0"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <combres definitionUrl="~/App_Data/CombresDevelopment.xml"  xdt:Transform="Inserting"/>
    <!--
    In the example below, the "SetAttributes" transform will change the value of 
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
    finds an atrribute "name" that has a value of "MyDB".

    <connectionStrings>
      <add name="MyDB" 
        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
  -->

  <system.web>        
      <!--
      In the example below, the "Replace" transform will replace the entire 
      <customErrors> section of your web.config file.
      Note that because there is only one customErrors section under the 
      <system.web> node, there is no need to use the "xdt:Locator" attribute.

      <customErrors defaultRedirect="GenericError.htm"
        mode="RemoteOnly" xdt:Transform="Replace">
        <error statusCode="500" redirect="InternalError.htm"/>
      </customErrors>
    -->
  </system.web>
</configuration>

【问题讨论】:

  • 错误路径“E:test.com”是实际错误路径,还是你匿名的东西?

标签: c# windows visual-studio-2010 asp.net-mvc-2 combres


【解决方案1】:

我理解它的方式是它不合并,而是使用新语法转换 web.config。发布和调试配置中应该有一些关于如何执行此操作的 cmets。

//In the example below, the "SetAttributes" transform will change the value of 
//"connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
//finds an atrribute "name" that has a value of "MyDB".

<connectionStrings>
  <add name="MyDB" 
    connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

正如它所说,此转换将替换连接字符串,但我确信您可以使用它来转换和替换 web.config 的任何其他部分。


在您的 web.release.config 中尝试

   <combres definitionUrl="~/App_Data/Combres.xml" xdt:Transform="SetAttributes"/>

web.debug.config

   <combres definitionUrl="~/App_Data/CombresDevelopment.xml" xdt:Transform="SetAttributes"/> 

我认为您的问题在于没有正确使用转换,您可以阅读此链接以获取更多信息。 http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx

【讨论】:

  • 嗯,不管它做什么,它似乎需要更多的东西,我想不通。
  • 我不完全确定您是如何修改 web.config 的。你的 web.release.config 是什么样的。它应该只包含您需要为该构建类型更改的内容。
  • 我可以发布它。请参阅我的编辑。我尝试添加该转换(我尝试替换、SetAttributes、删除)但同样的错误。如果您可以下载梳子并尝试制作自己的示例,看看是否遇到同样的错误,我们将不胜感激。
  • 您还说“需要更改该构建类型”我必须以任何特殊方式启动它还是 F5(调试模式足以获得调试 web.config?)
  • 按f5(调试)时是否出现此错误? - 如果是这样,我的解决方案将什么也不做,我认为在这种情况下甚至不会使用那些 web.release.config 等(调试时(f5)我认为它使用你的 web.config 并且不会应用任何变换)。 web.release.config 等仅在您使用发布时使用。见weblogs.asp.net/owscott/archive/2009/06/06/…这是你在做什么,还是只是用F5调试?
【解决方案2】:

似乎不是 web.config 问题。

错误是关于无法访问'E: test.com' 路径。

检查此文件的权限,错误应该消失,或者发现真正的错误。

问候

【讨论】:

  • 只是添加,直接检查文件而不是文件夹的权限。有时应对文件与安全性混淆 例如:在文件夹中设置权限,但复制内部具有不同指令的文件......文件夹将可用但文件不会。
  • 好的,我检查了他们对每个人都有权限的文件的权限,每个人都可以完全控制。我也添加了 iis_Iusrs 并完全控制。但我得到同样的错误。我真的认为有人需要在他们的计算机上进行实际快速测试并尝试一下。这样,如果可行,可以将其发送给我,我会尝试并比较不同之处。
【解决方案3】:

我希望你一定已经检查过了。但以防万一……

右键单击 APP_DATA 文件夹。在“属性”中的“安全”选项卡下检查运行 IIS 的登录名是否具有对 APP_DATA 文件夹的适当权限。

【讨论】:

  • 好吧,我把每个文件夹(包括那个)都放在“每个人”的权限上,“每个人”都有完全控制权。那么我必须添加其他用户吗?
  • 在大多数情况下,IIS 在一个登录名下运行,该登录名是&lt;machine name&gt;\IIS_IUSRS 用户组的成员。你应该给它一个write 权限。
  • 我认为有人需要使用这个库在他们的计算机上制作一个示例,看看他们是否遇到了同样的问题。这样我就可以得到那个副本并在我的计算机上进行测试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多