get session variable in runtime - asp.net

There are more web applications (asp.net 4) in own virtual directory of IIS server (under win2003).
And appertain to all own schema and account in oracle 11g database.
After login all users have some session variables (like username,shema name ...etc). I want to get these information for user management in runtime. How can I ask it from the server?

Maybe you are looking for this?
To retrieve:
string username = Session["Username"];
To put things on Session:
Session["Username"]="SomeValue";

Related

How to check which IIS application is calling the database

I have 2 application (websites) on one IIS and which is calling same remote database. Is there any thing in SQL server which will give me in stored procedure that who is calling :) ?
APP_NAME() returns the application name for the current session if set by the application. An another way of identifying the app is to log the app name through the CRUD operation , so that an additional field will be added in the tables to hold the app name.
You need to modify your connection strings and add Application Name
Data Source=myServer;
Initial Catalog=myDB;
User Id=myUsername;
Password=myPassword;
Application Name=myApp;
Now when you query sys.processes,program name will be application name
References:
http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/
https://www.connectionstrings.com/sql-server/
Check this thread if you are using VB.NET:
How to set "Application Name" in ADODB connection string
if not above will work

SSAS Error The MyCube either does not exist or has not been processed when attempting to query through ASP.NET

I have a cube, which has been processed, works from the BID environment, and I can run my MDX query in both SSEM, and the BID env. I've created a role that contains the proper accounts/permissions, processed, and deployed the cube, re-processed it in SSEM, etc. Now I'm trying to connect, and extract the data using ASP.NET 4.0, but I'm getting this error:
The MyCube either does not exist or has not been processed
Here's my code:
String connectionString = "Provider=MSOLAP.3; Data Source=myhost;Initial Catalog=myCatalog; User ID=myaccount; Password=myamazinglysecurepassword;";
String mdxSQL = " my MDX, which was taken directly from BID env. cube in design mode";
AdomdConnection connection = new AdomdConnection(connectionString);
connection.Open();
AdomdCommand cmd = new AdomdCommand(mdxSQL, connection);
CellSet cst = cmd.ExecuteCellSet();
...etc
Note: we are not using MSMDPUMP.dll to connect, we'd like to avoid that.
Any Ideas?
A couple things to consider. How are users authenticating to your web app? What account is your application pool running as?
If you're using Integrated Windows in ASP.NET you may be getting a double-hop issue if IIS and SSAS on different servers. This would require you to set up Kerberos and trusted delegation SPN's between your application and the OLAP service.
See (SSAS and IIS):
http://msdn.microsoft.com/en-us/library/dn194199.aspx
http://technet.microsoft.com/en-us/library/dd632778.aspx
Otherwise there may be an issue with the account your application pool is running under. I see in your connection string you have a specific account - so I presume you are trying to connect as one account rather than delegating user credentials to OLAP. The process running w3wp.exe is the identity which will attempt to connect to SSAS. If your application pool is not runnning as a domain account is may not be able to authenticate to SSAS.

ADOMD.net Impersonate Windows User ID

I am trying to connect to a SSAS Cube which uses windows authentication
My web application is stored on a seperate server the SQL Analysis Instance (lets says ServerWebApp) and the SSAS Cube is on ServerCUBE
OLAPCon = New AdomdConnection("Provider=MSOLAP.4; roles=Administrator; Integrated Security=SSPI; Persist Security Info=True; EffectiveUserName=<Domain\Username>; " _
& " Initial Catalog=<DBName>; Data Source=<ServerCUBE>; ")
As SSAS uses Windows authentication I have tried to impersonate my windows login by specifing EffectiveUserName however, this doesn't seem to work as I am getting the follow error:
Either the user, Domain\ServerWebApp, does not have access to the <DBName> database, or the database does not exist.
As you can see it is using the web apps login ID not my windows ID
How would I impersonate my windows ID in the SSAS ADOMD connection string?
This is what tripped me up when I used EffectiveUserName. From MSDN:
To use [the EffectiveUserName] property, the caller must have
administrative permissions in Analysis Services.
You need to configure the IIS server first by creating an Application pool first. Then you need to point this pool to the local path ( folder in C drive) which consists of msmdpump.dll and msmdpump files. Edit msmdpump file using notepad (remove localhost name and replace it with your SQL analysis server name). Provide the username of server name in place of domain\username.

Config IIS or ASP.NET to Use 'Login user' in Parallelism rather than 'IIS APPPOOL\\MyAppPool' User

I have a web site in ASP.NET 4 that need Connect to SQL Server 2008 R2 with Parallelism, Also Use IIS 7 and Windows authentication, I use Parallel.Foreach expression, When I use Foreach every thing is fine, but in Parallel.Foreach I get an error: Login failed for user: 'IIS APPPOOL\\MyAppPool'., So after some search I found need to change Process Model identity in Application pool From ApplicationPoolIdentity to LocalSystem:
Or I can add specific user:
But the last one is not a proper solution.
So I check in SQL SPs modified it and add line:
Then the result is: When I use foreach (mean without parallelism) all the registered user is MyLoginUser but with Parallel.foreach (And LocalSystem Identity) the first user registered is MyLoginUser and the others is NT Authority System.
Also I found Parallel Impersonation but not worked either and I got the same error.
As I understand MyLoginUser have not permission to Multi Connect to sql, Am I right?
if yes, so how can I add permission to this user?
In final I try to use ApplicationPoolIdentity and MyLoginUser to use Parallelism to connect to SQL. Does any one have any suggestion?
UPDATE:
I found that the first connection to db is the MyLoginUser then the ASP.NET try to connect more and let ApplicationPool do this, but the applicationpool can not login because have not permission and I also don't want to let it, the only user could connect must be myloginuser.
So the question could be:
How config IIS or ASP.NET to use myloginuser (the same of first user)
to connect with all connections to db (also in Parallel connections)?

Complains of a user that does not exist

I've specified the user of my application pool to be SERVER4\IUSR_SERVER4. And then I added this user to the SQL Server. But when I try to connect to the database I get the following error:
Server Error in '/BSHHD' Application.
Cannot open user default database. Login failed.
Login failed for user 'SERVER4\Administrator'.
What's driving me mad is there's no user named SERVER4\Administrator. What do I have to do in order to be able to properly connect to this SQL Server database from my website?
P.S. I think this is related with Membership authentication. Now I need to find out how Membership accesses SQL Server and where the login credentials are specified
The thing is, the app pool user is not necessarily the user you use to connect to MSSQL (as a guy in the comments already stated). After seeing your connection string, this is probably the case, and maybe, just maybe, the problem is not the user but it's default database.
I've had this error in the past: Try setting the user you use in the connection string (clerk's) default database to something else. This error is common when you've set a default database for a user before and now the database doesn't exist anymore or is having some problems.
You can change the user's default database using something like this:
Exec sp_defaultdb #loginame='clerk', #defdb='dok'
You can also use something like this but I've never used it:
ALTER LOGIN SQLLogin WITH DEFAULT_DATABASE = AvailDBName
Also, there's no need to set the integrated security to false because it is the default value already. I hope this helps =)

Resources