Failure to get NHibernate session when switching to Windows Authentication - asp.net-mvc

I'm trying to switch a working S#arp Architecture MVC application from an app pool with the Network Service identity to an app pool with a domain user identity. I ran aspnet_regiis on the user in the web server and gave the user permissions to access the database (even tried making it a sysadmin in the database). However, it seems like it can't get the NHibernate session.
Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
Request information:
Request URL: http://<redacted>
Request path: /<redacted>
User host address: 10.10.10.10
User: <webuser>
Is authenticated: True
Authentication Type: Forms
Thread account name: <MYDOMAIN\MYUSER>
Thread information:
Thread ID: 1
Thread account name: <MYDOMAIN\MYUSER>
Is impersonating: False
Stack trace: at SharpArch.Data.NHibernate.NHibernateSession.get_Current() in C:\MyStuff\Dev\Projects\SharpArchitecture\src\SharpArch\SharpArch.Data\NHibernate\NHibernateSession.cs:line 88
at UserAccount.Persistence.UserRepository.GetByPropertiesPartialMatching(IDictionary`2 exactMatchPropertyValuePairs, IDictionary`2 partialMatchPropertyValuePairs, MatchMode matchMode) in c:\Persistence\UserRepository.cs:line 66
...
The actual line giving the Null reference exception within SharpArch NHibernateSession.cs is:
ISession session = Storage.Session;

Clear your temp files on the server. I know it sounds crazy, but S# does file caching on the config.
I've done this several times, but have never seen the problem you are reporting. Do ANY of your calls to repositories (any of them) succeed or all but this one?
Here is what is sticking out to me. Your application spins up. If it had a connection issue, it would not be able to spin the application up. That is leading me to believe you might have another issue.

The root cause of this issue was that there was actually another exception before this one where NHibernate "couldn't compile the mapping document". The reason was that the .NET XMLSerializer needs write access to c:\windows\temp. I right-clicked this folder and added my application pool identity (a domain user) with Modify permission. It was fixed then.
This is all explained in NHibernate MappingException: Could not compile the mapping document
(So it was indeed related to temp files, Alec.)

Related

Getting a 403 Error After Session Timeout, Now Unable to Login or Logout

I have a website that requires a lot of data entry. It hasn't been an issue until recently. Now the user is getting a 403 error, which I assume is caused by the session timeout. The problem I am having is that now, every page gives you a 403 error, even the logout. So, until I clear all the site cookies, the user is unable to do anything. I have to believe there is a better way to resolve this without having to resort to clearing cookies. Thanks.
Wade
There are so many reasons behind the session timeout:
1)Application Pool is recycled
2)IIS/worker process is restarted
3)Application Domain is restarted.
4)Some times system admins(IIS server admins) restricted the applications due to heavy burden of database log files please check the database log files
First, check the iis log for the sub status code.try to set the session time and application pool recycle time the same value. iis ideal time out default value is 20 minutes.
you could also set the iis HTTP keep-alive setting by following below steps:
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/httpprotocol/
you can use the Auto-Start behavior to keep the app "Always Running".
https://weblogs.asp.net/scottgu/auto-start-asp-net-applications-vs-2010-and-net-4-0-series

Configuring Web Logic JMS Module with Oracle AQ Queues

I testing setting up a web logic server which can use an Oracle AQ JMS implementation, but for some reason my WLS connection pool cannot see the queue I have created, the only way I can see the find the queue in web logic is to make the web logic datasource connection pool use the credentials of the DB user who created the queue.
I have done the following as admin_user:
Created a Queue Table
EXECUTE DBMS_AQADM.CREATE_QUEUE_TABLE(queue_table=>'testqueue_table',queue_payload_type=>'sys.aq$_jms_text_message');
Created a Queue
EXECUTE dbms_aqadm.create_queue(queue_name=>'testqueue', queue_table=>'testqueue_table');
Started the Queue
EXECUTE dbms_aqadm.start_queue(queue_name=>'testqueue');
Granted the CPOOL user permissions
GRANT aq_user_role TO cpool;
EXECUTE DBMS_AQADM.grant_queue_privilege(privilege=>'ALL', queue_name=>'adming_user.testqueue', grantee=>'cpool',grant_option=>FALSE);
Set up 2 JDBC DataSources in Web Logic
I set up 2 datasources in web logic which connect to my database, both are identical except that one uses the cpool user and the other uses admin_user
Create JMS Modules
Now I register a jms module with the JDBC DataSources and wire up the local and foreign JDNI names.
If I use the DataSource which uses admin_user everything works fine and my deployed application can find queue in JNDI.
Problem
If I use the data source which uses cpool then it fails finds the connection pool in JNDI but never the Queue (despite the fact it worked for admin_user). I get the following error from WL:
Related cause:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testqueue': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Cannot resolve name:Queues/TESTQUEUE
Does anyone know why WL cannot resolve the JNDI name for the queue unless I use the admin_user account for my datasource.
The answer was that my connection pool user was missing some grants, the following where required:
GRANT EXECUTE on DBMS_AQ to <CPOOL>;
GRANT EXECUTE on DBMS_AQADM to <CPOOL>;
GRANT aq_user_role to <CPOOL>;
Make sure the user who creates the destination grants access to the connection pool user:
`EXECUTE DBMS_AQADM.grant_queue_privilege(privilege=>'ALL', queue_name=>'<SCHEMAOWNER>.docprod_queue', grantee=>'<CPOOL>',grant_option=>FALSE);`
Finally in Web Logic make sure to reference the destination by their full foreign JNDI name:
Queues/<SCHEMA OWNER>.<DESTINATION_NAME>

IIS conflict with Sql Server Reporting Services

When running in Visual Studio, my mvc3 app does not ask for any authentication. However, when I deployed to test server (Windows Server 2008 and IIS 7) I keep getting a prompt asking for UserName and Password. I supply the admin credentials for the server yet there is a failure. The strange thing is that the page is served but I keep getting the prompt. All the ajax calls however fail with a 401 Unauthorized error.
I tried different types of authentication but the results are the same. Even with anonymous authentication only I get a prompt for user name and password.
I tried changing the pipeline from Managed to Classic but then MVC would not work and I get 404 error. This is my first mvc app and I did not expect such issues in deployment.
Any clues how to get this to work?
==Edit begin===
This is what I suspect might be causing the issue. On the server the site is bound to test.xyz.com. Also, there is Sql Server Reporting Services Installed. My application is tries to query the url test.xyz.com/Reports but I think this is bound to SSRS. When I stop the SSRS service I get a service unavailable 503 error. Otherwise I get a authentication window.
I am trying to find out how can I remove the particular SSRS binding so that test.xyz.com/Reports points to my Reports Controller
==Edit end====
You can also use Reporting Services Configuration Manager to specify the port and url that Reporting Services uses on the server.
By default SQL Server Reporting Services uses the following urls:
http://<server name>/ReportServer // web service url
http://<server name>/reports // reports manager url
http://msdn.microsoft.com/en-us/library/ms159261(v=sql.105).aspx
Things to check:
Does your web application accessing any resources? If so, does the IIs worker process account have permission to those?
Have you set the Web Site Authentication to Enable anonymous access?
Do you by any chance doing impersonation (either in web.config of programmatically? If so, does the end user account have the proper permissions to any eventual back end resources?
I changed my controller from Reports to MyReports and this resolved the conflict.

StructureMap fails on IIS 7.5 with AppPoolIdentity

I have a problem with ASP.NET MVC application hosted on IIS 7.5 on separate application pool, configured with AppPoolIdentity and .NET 4.0 Framework.
The application is working normally for some time and suddenly part of controllers start to throw an exception inside StructureMap:
System.ArgumentNullException: Trying
to find an Instance of type [MyType]
Parameter name: instance
in
StructureMap.InstanceCache.Get(Type
pluginType, Instance instance) +376
The type requested was registered correctly (and was resolved properly just a minute before the exception occured). I can't verify it is still registered, as WhatDoIHave throws an exception, too:
NullReferenceException: Object
reference not set to an instance of an
object. in
StructureMap.Diagnostics.WhatDoIHaveWriter.writeInstance(InstanceRef
instance) +133
Looks like StructureMap's internal cache gets corrupted somehow.
The problem disappears when I change AppPoolIdentity to "real" local system user credentials. So it looks like the problem is somewhere between IIS and StructureMap. Maybe app pool recycling makes problems here? But it is configured to recycle every 1740 minutes and it fails sometimes after 5 minutes from its start...
Well, the problem appeared to be very different, I don't know how it may looked like connected to app pools and privileges.
The flaw is in GetNamedInstance<T> StructureMap's container method. I requesting a named instance, which is not registered, StructureMap tries to create the instance and add it to the container. Creation fails, but nevertheless, StructureMap registers null in the container. Each subsequent request for that named instance fails when encounter this null.
Our workaround is that we use GetAllInstances<T> instead of GetNamedInstance<T> and iterate manually through all instances of T to find matching one.

Msmq and WCF Service

I have created a WCF service using the NetMsmq binding for which i created a private queue on my machine and executed the project. This works fine as such and my WCF service is started and accesses the message using the queue in the debugging environment. Now, I wanted to host the service using the windows service and for the same I created a new project and windows installer as well (This service runs under Local System Account). Then I tried installing this windows service using the InstallUtil command through the command prompt. When installation is happening and during the service host opening, I get an exception saying:
There was an error opening the queue. Ensure that MSMQ is installed and running, the queue exists and has proper authorization to be read from. The inner exception may contain additional information.
Inner Exception System.ServiceModel.MsmqException: An error occurred while opening the queue:Access is denied. (-1072824283, 0xc00e0025). The message cannot be sent or received from the queue. Ensure that MSMQ is installed and running. Also ensure that the queue is available to open with the required access mode and authorization.
at System.ServiceModel.Channels.MsmqQueue.OpenQueue()
at System.ServiceModel.Channels.MsmqQueue.GetHandle()
at System.ServiceModel.Channels.MsmqQueue.SupportsAccessMode(String formatName, Int32 accessType, MsmqException& msmqException)
Could anyone suggest the possible solution for the above issue? Am I missing any permissions to be set for the queue as well as the windows service, if so could you suggest where should these permissions be added?
Tom Hollander had a great three-part blog series on using MSMQ from WCF - well worth checking out!
MSMQ, WCF and IIS: Getting them to play nice (Part 1)
MSMQ, WCF and IIS: Getting them to play nice (Part 2)
MSMQ, WCF and IIS: Getting them to play nice (Part 3)
Maybe you'll find the solution to your problem mentioned somewhere!
Yes, it looks like a permissions issue.
Right click on your private queue from the Server Manager, and select Properties. Proceed to the Security tab, and make sure you have the right permissions in there for your Local System Account.
This is also confirmed in Nicholas Allen's article: Diagnosing Common Queue Errors, where the author defines the error code 0xC00E0025 as a permissions problem.
I ran into same problem, here is the solution.
Right click "My Computer" --> Manage. In Computer Management window go to "Services and Applications --> Message Queueing --> ur queue", select ur queue and access properties. Add the user running ur WCF application and give full access. This should solve the issue.
Can simple be that the service can't find the it's queue.
The queue name must exact match the endpoint address.
Example:
net.msmq://localhost/private/wf.listener_srv/service.svc
points to local queue
private$\wf.listener_srv\service.svc
If queue name and endpoint are according to each other, then is most like that the credentials defined on the IIS pool don't grant access to the queue.

Resources