Web App works on localhost but fails on remote connection - asp.net

We have a new ASP.NET web application we are deploying that uses a separate DLL which we also built which in turn interrogates the Active Directory for simple user and group membership information. The server is Windows Server 2003.
The application works fine if I RDP to the server and browse it under localhost.
The application throws the following error when I browse to it from a separate PC. It also throws the same error if I browse to it from the RDP session on the server, but browse it under the server name.
Is this a code-access security issue? Other ideas?
Exception Details: System.Runtime.InteropServices.COMException: An operations error occurred.
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:
[COMException (0x80072020): An operations error occurred.
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +420085
System.DirectoryServices.DirectoryEntry.Bind() +36
System.DirectoryServices.DirectoryEntry.get_Name() +32
USM.UsmAD.get_DomainName() in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\Active Directory Search\USMAD\USMAD\UsmAD.cs:60
USM.UsmAD.Get_UserGroupNames(String username) in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\Active Directory Search\USMAD\USMAD\UsmAD.cs:190
AdminWeb.CheckAccessDAL.GetGroupNames() in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\USMDAL\CheckAccessDAL.cs:28
AdminWeb.CheckAccessDAL.SetMenuAccess(Menu mnuUSMAdmin) in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\USMDAL\CheckAccessDAL.cs:89
AdminWeb.SiteMaster.TrimMainMenus() in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\AdminWeb\Site.Master.cs:50
AdminWeb.SiteMaster.Page_Load(Object sender, EventArgs e) in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\AdminWeb\Site.Master.cs:17
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

sounds like a perms issue on the dll
try allowing IUSR access to this file....

You will probably need to run your app pool under an domain level identity that has permission to access the resources it needs to talk to Active Directory.
Specify an Identity for an Application Pool (IIS 7)
Configuring Application Pool Identity with IIS 6.0 (IIS 6.0)
Here is an article if you need to do this at runtime:
How To: Use Impersonation and Delegation in ASP.NET 2.0
I also encourage you to implement an UnhandledException handler to log these run-time errors.

Related

Stored procedure found on localhost but can't be found when published

I have a stored proc on a server. The same server is used in both local development and the remote Dev server I have.
The site functions fine when I run it in debug on my local machine. When I publish it returns:
The stored procedure 'vts_spUserGetUserIdFromUserName' doesn't exist.
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.InvalidOperationException: The stored
procedure 'vts_spUserGetUserIdFromUserName' doesn't exist.
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:
[InvalidOperationException: The stored procedure
'vts_spUserGetUserIdFromUserName' doesn't exist.]
System.Data.SqlClient.SqlCommand.DeriveParameters() +3962
System.Data.SqlClient.SqlCommandBuilder.DeriveParameters(SqlCommand
command) +127
Microsoft.Practices.EnterpriseLibrary.Data.Database.DiscoverParameters(DbCommand
command) +154
Microsoft.Practices.EnterpriseLibrary.Data.ParameterCache.SetParameters(DbCommand
command, Database database) +114
Microsoft.Practices.EnterpriseLibrary.Data.Database.AssignParameters(DbCommand
command, Object[] parameterValues) +42
Microsoft.Practices.EnterpriseLibrary.Data.Database.GetStoredProcCommand(String
storedProcedureName, Object[] parameterValues) +70
Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteScalar(String
storedProcedureName, Object[] parameterValues) +38
Votations.NSurvey.SQLServerDAL.User.GetUserByIdFromUserName(String
userName) +226
Votations.NSurvey.WebAdmin.NSurveyAdmin.UserControls.LoginBox.ValidateCredentialsButton_Click(Object
sender, EventArgs e) +168
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11761917
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +150 System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+6016
The stored proc is definitely there. I have KDiff'd the two web.config files and there are no differences.
The only issue I can think of is that on the server it is in a Web Application as a sub application of another root site. Could that be the reason. It is inheriting database connection strings from the other application? If so is there any way I can stop that behavior?
Check the schema under which the Stored Procedure is created.
I might be possible that the Stored Procedure is created under your account, that is why when you are running it on local machine its able to find the SP and not when its running under some other account on sever.

ASP.NET - Accessing Active Directory from code behind page

I have made a web application, which reads/writes from/to Active Directory. In my web.config file there is
<identity impersonate="true"/>
and
<authentication mode="Windows"/>
When I display
System.Web.HttpContext.Current.User.Identity.Name
in some label, it shows mydomain\myusername, so I think impersonation works.
Now to the question. When I access the application on the server, where the IIS web server is running, everything works great. But when I access the web application from a remote PC, I get an exception (the label still shows "mydomain\myusername").
I have traced the problem down. In the code behind when I call
Forest currentForest = Forest.GetCurrentForest();
the variable currentForest knows its currentForest.Name, currentForest.RootDomain or currentForest.ForestMode, but any call to currentForest.Domains, currentForest.Sites or currentForest.GlobalCatalogs results in
System.DirectoryServices.ActiveDirectory.ActiveDirectoryOperationException.
Now I'm lost and don't know what to debug further. The account I'm using is member of Enterprise Admins (multi-domain forest). I have tried it on two different servers with different IIS versions (IIS 7.5 and IIS 6.0) with no luck.
And the thrown exception isn't of much help:
Exception Details: System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.
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:
DirectoryServicesCOMException (0x80072020): An operations error occurred.
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +557
System.DirectoryServices.DirectoryEntry.Bind() +44
System.DirectoryServices.DirectoryEntry.get_AdsObject() +42
System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) +98
System.DirectoryServices.ActiveDirectory.ADSearcher.FindAll() +46
System.DirectoryServices.ActiveDirectory.Forest.GetDomains() +543
[ActiveDirectoryOperationException: An operations error occurred.]
System.DirectoryServices.ActiveDirectory.Forest.GetDomains() +512484
System.DirectoryServices.ActiveDirectory.Forest.get_Domains() +44
myWebApp.ASPpage.Button_Click(Object sender, EventArgs e) in C:\Documents and Settings\myUser\documents\visual studio\Projects\MyWebApp\MyWebApp\ASPPage.aspx.cs:158
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
EDIT: If it is not obvious, I want to use currentForest.Domains to search the whole forest (all domains) for a user given by UPN name.
I found the answer to my question in one of "Related questions" on this page. The answer was in this topic: Why does DirectoryServicesCOMException occur querying Active Directory from a machine other than the web server?
I found, that it was exactly my case. After reading the suggested Microsoft article, I learned, that impersonating works only for local resources on the IIS server. To access network resources (SQL, Active Directory), I have to set "Trust this computer for delegation" in the computer object in Active Directory.
It was because the IIS always authenticate therefore System.Web.HttpContext.Current.User.Identity.Name showsmydomain\myusername; to verify that the impersonation works you could use:
System.Security.Principal.WindowsIdentity.GetCurrent().Name, also the System.Security.Principal.WindowsIdentity.GetCurrent(true) returns null when it is not impersonating.

WF 4.0 can't get to resume workflow on the staging/production environment

I have developed various registeration workflows using WF4.0. Each work flow has various bookmarks. I am using the registeration wf for an asp.net application.
I tested the asp.net application locally and it is working fine( Starting WF, Persisting to db and resuming bookmarks). When I try to test it on the staging server, everything goes messy. I can no longer resume wfs and I get an error message :
System.Runtime.DurableInstancing.InstancePersistenceCommandException
was unhandled by user code Message=The execution of the
InstancePersistenceCommand named
{urn:schemas-microsoft-com:System.Activities.Persistence/command}LoadWorkflow
was interrupted by an error. Source=System.Runtime.DurableInstancing
StackTrace:
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.Runtime.DurableInstancing.InstancePersistenceContext.OuterExecute(InstanceHandle
initialInstanceHandle, InstancePersistenceCommand command, Transaction
transaction, TimeSpan timeout)
at System.Runtime.DurableInstancing.InstanceStore.Execute(InstanceHandle
handle, InstancePersistenceCommand command, TimeSpan timeout)
at System.Activities.WorkflowApplication.PersistenceManager.Load(TimeSpan
timeout)
at System.Activities.WorkflowApplication.LoadCore(TimeSpan timeout, Boolean loadAny)
at System.Activities.WorkflowApplication.Load(Guid instanceId, TimeSpan timeout)
at System.Activities.WorkflowApplication.Load(Guid instanceId)
at CEO_StartUpCEORegisterationTest.LoadInstance(Guid wfInstanceId) in c:\Users\Kunoichi\Documents\Visual Studio
2010\Projects\CMERegistrationSystem\RegistrationPortal\CEO\StartUpCEORegisterationTest.aspx.cs:line
64
at CEO_StartUpCEORegisterationTest.Page_Load(Object sender, EventArgs e) in c:\Users\Kunoichi\Documents\Visual Studio
2010\Projects\CMERegistrationSystem\RegistrationPortal\CEO\StartUpCEORegisterationTest.aspx.cs:line
44
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: System.Data.SqlClient.SqlException
Message=Index 'NCIX_KeysTable_SurrogateInstanceId' on table 'KeysTable' (specified in the FROM clause) does not exist.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=211
Number=308
Procedure=LoadInstance
Server=
State=1
StackTrace:
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.Activities.DurableInstancing.SqlWorkflowInstanceStoreAsyncResult.SqlCommandAsyncResultCallback(IAsyncResult
result)
I know that this is quite verbose. But I have been banging my head against the wall for more than a week. I did search and all I came to know was to work on ms dtc. I enabled it on the staging server , I installed application server on the staging server and I am still getting the same error. I would appreciate if anyone could help with the problem. Thanks in advance :)
Who created the persistence store being used on the staging server? What schema was used to create it? Look for differences between the scripts used locally and in production.

Execution of the command requires an open and available connection. The connection's current state is broken

Serious problem with entity framework & sql server 2008, please help!!
System works well locally but during load test at production server we have following error for more then 10 users.
After get this error user can not logged in anymore.
Server Error in '/' Application.
Execution of the command requires an open and available connection. The connection's current state is broken.
Here is SQL Server Log
3005
An unhandled exception has occurred.
9/13/2011 3:41:14 AM
9/13/2011 7:41:14 AM
73b3f335f4de45fa8c4ef2f22809300b
4911
482
0
/LM/W3SVC/14/ROOT-3-129603711416579333
Full
/
E:\WebSites\Medtrack2.0\
COLO-VDEV01
15864
w3wp.exe
NT AUTHORITY\NETWORK SERVICE
InvalidOperationException
Execution of the command requires an open and available connection. The connection's current state is broken. at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source) at Dashboard.Page_Load(Object sender, EventArgs e) at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
http://38.127.112.89:9010/Dashboard.aspx
/Dashboard.aspx
119.148.4.83
JMiranda
True
Forms
NT AUTHORITY\NETWORK SERVICE
11
NT AUTHORITY\NETWORK SERVICE
False
at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source) at Dashboard.Page_Load(Object sender, EventArgs e) at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
have any idea?
See if the answer to this similar question can help you:
EF recovery from invalidoperationexception caused by server being down
or this one:
Exception: Execution of the command requires an open and available connection. The connection's current state is broken.
How are you storing the ObjectContext? From an EF perspective, you have to make sure each user gets a unique reference to the ObjectContext. To do that, I share the ObjectContext by storing it in the HttpContext.Current.Items collection. See this for more information on the Items collection: http://abhijitjana.net/2011/01/14/when-we-can-use-httpcontext-current-items-to-stores-data-in-asp-net/

'License expired' error when dynamically generating Excel docs in ASP.NET

Anyone familiar with error below? When I run my webapp to generate a dynamic excel doc from my local machine it works fine but when the same piece of code is invoked on the server I get the below error. It seems like it's a permissions issues since it works on my machine but not the server but I don't know where to start in order to pinpoint the problem. Any guidance/help is greatly appreciated!
Server Error in '/' Application.
--------------------------------------------------------------------------------
This command is unavailable because the license to use this application has expired.
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.Runtime.InteropServices.COMException: This command is unavailable because the license to use this application has expired.
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:
[COMException (0x800a03ec): This command is unavailable because the license to use this application has expired.]
Microsoft.Office.Interop.Excel.Workbooks.Add(Object Template) +0
PaymentsReport.Page_Load(Object sender, EventArgs e) +70
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
Office/Excel is installed on the server and I can open/save excel docs on the server. Could it be the version of excel on the server vs. my local machine? If so how can I make sure I have the latest on the server?
Apart from being installed, you need to make sure the application is activated on the server:
http://support.microsoft.com/kb/294973
Has details on how to do this.
Using Office Interop requires that the Office components you're using actually be installed on the server.
I'm gonna take a WAG and say that you just can't slap any old copy of Office on a server and let multiple users access it via your website. You need to look at the licensing restrictions for using MS office in a server environment.
Do you have a licensed, activated copy of Excel on the server? It probably works on your local machine because you have Office/Excel installed locally.

Resources