c# - 异常 : User does not have permission to perform this action

标签 c# .net asp.net-mvc sql-server-2008-r2

我一直在 visual studio 中使用我的网站 (ASP.NET MVC),但现在我想将它托管在我的服务器上。我从 visual studio 发布到要使用的网络共享上。服务器正在运行 Windows Home Server、IIS 6 和 SQL Server 2008 R2 (express)。

在 Microsoft SQL Server Management Studio 中,我附加了数据库并确保用户 IUSR_SERVER 是数据库的所有者。我还确保用户网络服务具有访问权限。

该网站在 IIS 中配置为以 IUSR_SERVER 匿名运行。我已授予对 IUSR_SERVER 以及文件系统中的网络服务的写入和读取访问权限,并确保没有任何内容是只读的。

web.config 有这个连接字符串:

        <connectionStrings>
    <remove name="ApplicationServices" />
  <add name="ApplicationServices" connectionString="Data Source=.\SQLExpress;Integrated Security=True;Initial Catalog=MyDatebase"
   providerName="System.Data.SqlClient" />
     </connectionStrings>

但是,我无法浏览我的网站。我只得到这个错误:

Server Error in '/' Application.

User does not have permission to perform this action. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: User does not have permission to perform this action.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): User does not have permission to perform this action.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846887 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194

感觉我什么都试过了。非常感谢您在这方面的帮助。

编辑:

This is the event in the event viewer:
Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 2010-06-05 23:55:08 
Event time (UTC): 2010-06-05 21:55:08 
Event ID: 88a3a76c00a34e21bf6e711b3b3a8f21 
Event sequence: 137 
Event occurrence: 59 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/6893/Root-2-129202466028125000 
    Trust level: Full 
    Application Virtual Path: / 
    Application Path: C:\Inetpub\WebPage\ 
    Machine name: SERVER 

Process information: 
    Process ID: 5864 
    Process name: w3wp.exe 
    Account name: SERVER\USER

Exception information: 
    Exception type: SqlException 
    Exception message: User does not have permission to perform this action. 

Request information: 
    Request URL: http://localhost/ 
    Request path: / 
    User host address: 127.0.0.1 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: SERVER\USER

Thread information: 
    Thread ID: 1 
    Thread account name: SERVER\USER
    Is impersonating: True 
    Stack trace:    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
   at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
   at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)     

Custom event details: 

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

最佳答案

原来问题是我的 DataContext 使用它自己的连接字符串,它不在 web.config 中。因此,它从未更改,无法建立连接。我更改了我的代码,以便我的数据上下文使用来自 web.config 的字符串并且它有效:)

关于c# - 异常 : User does not have permission to perform this action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2953137/

相关文章:

c# - 代码优先更改桥实体表的名称

c# - WAN 上的 TCP/UDP 套接字服务器

c# - 将 @Html.Raw 转换为 ASP.NET MVC 4 Razor 中的字符串

C# WPF - ListView 绑定(bind)不起作用

.net - .NET 中的托管资源与非托管资源。有什么不同?

c# - 如何为自定义 map 类实现具有内联初始化的构造函数?

c# - 序列包含多个元素

c# - Web API 将自定义异常对象转换为基本异常

asp.net-mvc - Visual Studio 2013 'add controller'丢失

c# - 发布可观察对象时异步创建挂起