2013-02-04 63 views
1

我正在使用SimpleMembership为ASP.Net MVC 4应用程序。SimpleMembership要求App_Data文件夹

连接字符串被配置为在开发和生产中都使用SQL Server而不是LocalDB。这很好,除了在没有App_Data文件夹的生产环境中,SimpleMembership尝试在应用程序池被回收(始终可重现)后,首次访问网站上的HTTP请求时访问App_Data。对于后续的HTTP请求,它不会尝试访问App_Data。

如果我预先创建App_Data并授予读/写权限,则不会引发错误。 App_Data中没有创建文件。

有什么我可以配置(短创建一个虚拟的App_Data文件夹在生产中),以防止这种“虚拟”访问尝试?

参考堆栈跟踪:

2013-02-04 21:10:27.4133 FATAL Global Exception. Status 500, Message: Access to the path 'C:\inetpub\MyWebApp\App_Data' is denied. 
2013-02-04 21:10:28.5643 ERROR at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 
    at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost) 
    at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost) 
    at System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) 
    at System.Web.DataAccess.SqlConnectionHelper.EnsureDBFile(String connectionString) 
    at System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) 
    at System.Web.Security.SqlRoleProvider.GetRolesForUser(String username) 
    at WebMatrix.WebData.SimpleRoleProvider.GetRolesForUser(String username) 
    at System.Web.Security.RolePrincipal.IsInRole(String role) 
    at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate) 
    at System.Web.Mvc.AuthorizeAttribute.AuthorizeCore(HttpContextBase httpContext) 
    at System.Web.Mvc.AuthorizeAttribute.OnAuthorization(AuthorizationContext filterContext) 
    at System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor) 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__1e(AsyncCallback asyncCallback, Object asyncState) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag) 
    at System.Web.Mvc.Controller.<>c__DisplayClass1d.<BeginExecuteCore>b__17(AsyncCallback asyncCallback, Object asyncState) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) 
    at System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate endDelegate, Object tag) 
    at System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) 
    at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__2(AsyncCallback asyncCallback, Object asyncState) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate endDelegate, Object tag) 
    at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) 
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

回答

1

你应该InitializeSimpleMembershipAttribute.cs开始与线“WebSecurity.InitializeDatabaseConnection(......)”复制到Application_Start方法中的开始在Global.asax中

protected void Application_Start() 
{ 
    WebSecurity.InitializeDatabaseConnection("MyDBContext", "UserProfile", "UserId", "UserName", autoCreateTables: true); 

    AreaRegistration.RegisterAllAreas(); 
    WebApiConfig.Register(GlobalConfiguration.Configuration); 
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
    RouteConfig.RegisterRoutes(RouteTable.Routes); 
    BundleConfig.RegisterBundles(BundleTable.Bundles); 
    AuthConfig.RegisterAuth(); 
} 
相关问题