首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用户代码无法处理Web.config.debug/release....System.UnauthorizedAccessException MVC2.0中的问题

用户代码无法处理Web.config.debug/release....System.UnauthorizedAccessException MVC2.0中的问题
EN

Stack Overflow用户
提问于 2010-06-22 22:18:45
回答 3查看 2.1K关注 0票数 0

我正在尝试使用webconfig的调试和发布版本,但它从未起作用。我试图这样做的第三方图书馆,我正在使用的称为梳子。

http://combres.codeplex.com/

因此,我首先将所有所需的web.config代码放在web.config中。现在我有了两个不同的.xml文件(这就是您放置javascript和css路径的地方)。

因此,生产将有一个不同的.xml路径和调试。

因此,我将这一行移到web.config的发布和调试中,并更改了xml文件的路径。

代码语言:javascript
复制
    // release webconfig
    <combres definitionUrl="~/App_Data/Combres.xml" />

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

我明白了

代码语言:javascript
复制
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

代码语言:javascript
复制
    <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

代码语言:javascript
复制
<?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>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-06-28 12:48:20

我理解它的方式是它不合并,而是使用新的语法转换web.config。在发行版中应该有一些注释,并就如何做到这一点向调试人员倾诉。

代码语言:javascript
复制
//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

代码语言:javascript
复制
   <combres definitionUrl="~/App_Data/Combres.xml" xdt:Transform="SetAttributes"/>

web.debug.config

代码语言:javascript
复制
   <combres definitionUrl="~/App_Data/CombresDevelopment.xml" xdt:Transform="SetAttributes"/> 

我认为您的问题是不正确地使用转换,您可以阅读此链接获得更多信息。链接

票数 2
EN

Stack Overflow用户

发布于 2010-07-01 14:04:02

似乎不是web.config问题。

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

检查这个文件的权限,错误就会消失,或者发现真正的错误。

问候

票数 1
EN

Stack Overflow用户

发布于 2010-06-28 12:41:41

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3097563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档