我正在開發一個安裝程序(EXE文件),它將部署和配置ASP.NET網站和相應的ASP.NET成員數據庫。System.Web在App.Config中的RoleManager在運行時缺失或無效
我有以下的app.config一個控制檯應用程序,其中包括的System.Web部分:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="LocalSqlServer1" connectionString="Server=.\NAME;Database=aspnetdb;Integrated Security=true" />
</connectionStrings>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog" />
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
<system.web>
<roleManager defaultProvider="SqlProvider1"
enabled="true"
cacheRolesInCookie="true"
cookieName=".ASPROLES"
cookieTimeout="30"
cookiePath="/"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
cookieProtection="All" >
<providers>
<add
name="SqlProvider1"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="LocalSqlServer1"
applicationName="SampleApplication" />
</providers>
</roleManager>
</system.web>
</configuration>
不過,我似乎無法得到角色或成員的工作,不管是什麼我做app.config。就好像整個system.web部分無效或缺失一樣。大多數情況下,我收到下面的錯誤消息,有時會得到「角色未啓用」。
是否有可能利用ASP.NET成員資格和角色在一個控制檯應用程序?並通過system.web部分配置正常的方式?如果是這樣,怎麼樣?請注意,Visual Studio項目保存在網絡共享中。
更新 - 按要求編譯器設置
更新 - 請注意,它正在從網絡共享
異常的內例外,這是一個安全性異常運行,由於該解決方案是在網絡共享上引起的,任何能夠提供修補程序以從網絡共享中運行解決方案的人都將獲得賞金!
更新 - 異常詳細的要求
System.Configuration.ConfigurationErrorsException was unhandled
BareMessage=An error occurred creating the configuration section handler for system.web/roleManager: Request failed.
Filename=L:\InternetSharePointRepository\InternetSharePointSolution\InternetSharePointConsoleApplication1\bin\Debug\InternetSharePointConsoleApplication1.vshost.exe.Config
Line=34
Message=An error occurred creating the configuration section handler for system.web/roleManager: Request failed. (L:\InternetSharePointRepository\InternetSharePointSolution\InternetSharePointConsoleApplication1\bin\Debug\InternetSharePointConsoleApplication1.vshost.exe.Config line 34)
Source=System.Web
StackTrace:
at System.Web.Security.Roles.Initialize()
at System.Web.Security.Roles.EnsureEnabled()
at System.Web.Security.Roles.CreateRole(String roleName)
at InternetSharePointConsoleApplication1.Module1.Main() in L:\InternetSharePointRepository\InternetSharePointSolution\InternetSharePointConsoleApplication1\Module1.vb:line 7
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Security.SecurityException
GrantedSet=""
Message=Request failed.
PermissionState=<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Level="Minimal"/>
</PermissionSet>
RefusedSet=""
Source=mscorlib
Url=""
StackTrace:
at System.Reflection.MethodBase.PerformSecurityCheck(Object obj, RuntimeMethodHandle method, IntPtr parent, UInt32 invocationFlags)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Configuration.TypeUtil.InvokeCtorWithReflectionPermission(ConstructorInfo ctor)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
InnerException:
這不是您原來的問題的答案:「是否可以在控制檯應用程序中使用ASP.NET成員資格和角色?並通過system.web部分配置常規方式?如果是這樣,怎麼辦?」 – TrevorBrooks
確實如此,但它在「更新它從網絡共享運行」後不久用粗體顯示。堆棧溢出允許您編輯問題,因爲我現在已經這麼做了,以便更清楚。不要指望被我授予獎金的人投票!大多數人會很高興收到獎勵? –
通常,兩個單獨的問題是兩個單獨的帖子。 – TrevorBrooks