Web site using using active directory groups slows to a crawl intermittently - active-directory

I have an asp.net mvc web site on an intranet. Access to the site is determined by groups in active directory. There are 4 different groups each having different access in the site. I have been having occasional problems with the site running slowly. The site will run fine for several days then suddenly slow to a crawl. I have both a test site and a production site. When the slowdown occurs both sites are affected equally. I also have a site that test site that has no active directory access and it runs with no problems while these two sites are crawling. The sites I am having trouble are running under a user account because the application has to reach out to another share on the intranet in order to print and merge pdf files. The sites are running under the same application pool. When the problem occurs, all pages are equally slow even pages with no database activity. When the problem occurs I reset IIS, restart the web sites, and recycle the threads. The only thing that actually resolves the problem is restarting the server. Sometimes it takes a additional restart to get the site back to normal. Here are a few things I have tried. It seems the problem is occurring less often but still occurs.
1. Reduce the numbers of times that I query active directory.
2. Reset IIS when the problem occurs. This has not been helping.
3. Recycle application pools.
4. Restart the sql server service
5. Made sure fully qualified names are used when referring to servers. This seems to have reduced the problems some. Not sure though. I am using IIS 7 on a windows 2008 server, 64 bit.
user = ConfigurationManager.AppSettings["TravelCardUser.AD_GroupName"];
approver = ConfigurationManager.AppSettings["TravelCardApprover.AD_GroupName"];
maintenance = ConfigurationManager.AppSettings["TravelCardMaintenance.AD_GroupName"];
admin = ConfigurationManager.AppSettings["TravelCardAdmin.AD_GroupName"];
testuser = ConfigurationManager.AppSettings["TestUser"];
List<string> adgroups = new List<string>();
adgroups.Add(admin);
adgroups.Add(approver);
adgroups.Add(maintenance);
adgroups.Add(user);
this.groups = adgroups;
List<string> groupmembership = new List<string>();
foreach (var group in groups)
{
if (!String.IsNullOrEmpty(testuser))
{
this.username = testuser;
}
else
{
this.username = currentloggedinuser;
}
using (var ctx = new PrincipalContext(ContextType.Domain))
using (var groupPrincipal = GroupPrincipal.FindByIdentity(ctx, group))
using (var userPrincipal = UserPrincipal.FindByIdentity(ctx, username))
{
if (groupPrincipal != null)
{
try
{
if (userPrincipal.IsMemberOf(groupPrincipal))
{
groupmembership.Add(group);
}
}
catch (Exception ex)
{
string theexception = ex.ToString();
}
}
}
}
Here is my ldap connection string.
<add name="ADConnectionString_UserRole" connectionString="LDAP://locationX/cn=TravelCardUser,ou=LocationXgroupsGroups,dc=acme,dc=us,dc=com" />

Ther server slows down every 3 or 4 days so I shut down the application pools to my applications and used Sysinternals to monitor process for 3 days.
http://technet.microsoft.com/en-us/sysinternals/bb896653
I am seeing that processes related to sequal server and team foundation server are grabbing resources but not releasing them. By the way I ran my asp.net code through Red Gate Memory Profiler and there are no memory leaks. Now I have to figure out what to do about the problem with memory usage.

Related

How to connect to SQL Server with Flutter?

I have to use SQL Server with Flutter and I don't have another database option because my client has it. I was looking for packages but I only found a package that doesn't run on mobile. Is there any option to do that without web services or api?
The first thing that you need to consider is that there is no immediate and extremely effective solution and you have to decide what frameworks and tools to be used. And as mentioned in the comment that the market for this scenario is very small. But there are some ways that you can handle this.
Remote storage sample solution:
Here is a basic example of how you should implement this. It was also cited in this SO post:
Client application
The client application can be any application the user typically uses.
Some examples:
Mobile app (written in native, Dart, Xamarin, ...)
Desktop app (Electron, WPF, ...)
Website app (Angular, React, Vue, ...)
API
The API is there to retrieve data, and change data. But It will also
handle authentication, authorization, logging, doing business logic
Database
Your API will then execute queries, inserts, updates, deletes, execute
stored procedures on the Database of your choice. In your example SQL
Server.
There are many possibilities on how to set this up, depending on your
skills, knowledge of frameworks, how you want to deploy things.
How you want to deploy this will limit your choices as well. For your
API:
Serverless API (Via Azure Functions, AWS Lambda)
Cloud Website (Azure Web Apps)
Website hosted on premise
Docker container
In real life scenarios this often gets more complex with Firewalls,
Application Gateways, Virtual networks, clusters.
You can install a SQLServerSocket on your server:
https://github.com/nippur72/SqlServerSocket
Install and execute SqlServerSocket.exe in the background on the server machine where SQL Server is installed.
Also, you need a client:
https://github.com/nippur72/SqlServerSocket/tree/master/DartClient
And you can try some connections and queries directly to your DDBB:
// creates a connection
var conn = new
SqlConnection("SERVER=localhost;Database=mydb;Trusted_connection=yes");
// open connection
await conn.open();
// runs a query returning a single value
var howmany = await conn.queryValue("SELECT COUNT(*) FROM Customers");
// runs a query returning a single row
var myFirstCustomer = await conn.querySingle("SELECT name,age FROM Custormers");
print(myFirstCustomer["name"]);
// runs a query returning all rows
var customers = await conn.query("SELECT TOP 10 name,age FROM Custormers");
for(var customer in customers)
{
print(customer["name"]);
}
// execute a command, returning the number of rows affected
var n = await conn.execute("UPDATE Customers SET age=0");
print("zeroed $n customers");
// disconnect
await conn.close();

Kestrel ASP.NET takes a long time to get photo hosted on local server, quicker when running the ASP.NET server on a remote computer

Hey guys hopefully the title wasn't too bad, hard to describe succinctly.
So I have an ASP.net core 2.0 server running (via Kestrel) on a VPS hosted in Australia (I'm in New Zealand, ~50ms latency to server). An HTTP Get action causes the following code on the ASP.net server to run, where I query an SQL server (also running on the vps) and return the result:
public async Task<string> GetTopContactPhoto(int contactUID)
{
// Open connection if not already open
if (conn.State != System.Data.ConnectionState.Open) { conn.Open(); }
// Get number of rows
string sqlRequest = string.Format("select top 1 imageData from IMAGES where contactUID=#contactID;");
// Return value
using (SqlCommand cmd = new SqlCommand(sqlRequest, conn))
{
cmd.Parameters.AddWithValue("#contactID", contactUID);
return Convert.ToBase64String((byte[])await cmd.ExecuteScalarAsync());
}
}
Now this whole process takes pretty consistently ~5-6 seconds from the time the HTTP Get request is made, to the time the result is given, image sizes ~2MB.
But here's the thing, when I compile and run the ASP.Net core server on my development PC, on a separate continent altogether to the VPS (still running the SQL server), the whole process takes only ~2 seconds, less if I resize the image before responding to Get request.
Any ideas what could be going wrong? This problem has vexed me for months, with no amount of googling doing the trick.

Accessing Local Settings in Windows 10

I am developing a Line-of-Business app for a client. The client specified the devices that were supposed to be used (some Dell tablet with Windows 8.1). Now, that the development is almost done and we were ready to release the first phase of the application, the client informed us that they have changed their mind and all those Dell tablets will run windows 10. I upgraded one tablet that I used for development and testing to Windows 10 as well. The tablet uses a RESTful Web API to access data stored in a repository. Obviously, the URL of the Web API must be configured in the settings of the app before the app can retrieve any data from the repository.
So I create the App Package to sideload the app on the tablet. The installation works properly, the app starts well for the first time. I go into the settings, set the URL and close the app.
When I try to restart, the app gets stuck showing the Splash Screen. If I try to access the Settings, I am informed that the settings for my app are not available at that time. The only way to get out of this is to uninstall the app and reinstall it again.
This is the code I use to save and retrieve the settings:
public void SaveSetting<T>(string settingName, T value)
{
ApplicationData.Current.LocalSettings.Values[settingName] = value;
}
public T GetSetting<T>(string settingName)
{
var localSettings = ApplicationData.Current.LocalSettings.Values;
if (localSettings.ContainsKey(settingName))
{
var value = localSettings[settingName];
if (value is T)
{
return (T)value;
}
}
// else, in all other cases
return default(T);
}
An interesting thing I noticed is that sometimes, depending on what I try to save in the settings, the app starts. For example, I was playing with it and tried to save some garbage instead of the correct URL. So instead of "http://x.x.x.x:nnnnn" I saved "a". The app started correctly, I got past the splash screen but obviously, I couldn't get any data.
Any ideas as to what exactly is happening? Did the access method for local settings change in Windows 10?
I have been scratching my head over this for the past couple of days. Initially, I thought it is a matter of permissions to create the Local Settings file, so I dedicated a lot of energy trying to find a solution from that perspective. However, as I said, if I dump some garbage in the settings, it works, so it's not a matter of permissions. Could it be that and IP address like "x.x.x.x" needs to be saved in a different way than as a string?
Any advice would be highly appreciated.
TIA,
Eddie
After I added some logging to my application I was able to prove that the app had no issues reading the settings. It's what it tried to do with them that it did not work. The URL read from the settings was correct but when the app tried to make calls to the Web API, the calls threw an exception and the app stopped working. So this shouldn't have been a question in the first place.
Thanks, Eddie

Google drive api 500 error in 80% of requests on app engine

I'm using Drive API on Google app engine.
Application servers 7k request per day.
During last day number of errors from api increased to nearly 60%.
{ "code" : 500, "message" : null }
I use this code to initialize drive:
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
AppIdentityCredential credential =
new AppIdentityCredential.Builder(Arrays.asList(DriveScopes.DRIVE)).build();
GoogleClientRequestInitializer keyInitializer =
new CommonGoogleClientRequestInitializer(Settings.API_KEY);
Drive service = new Drive.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential)
.setApplicationName(APP_NAME)
.setGoogleClientRequestInitializer(keyInitializer)
.build();
return service;
Does any one have same situation?
Are there any solutions?
Thanks!
UPDATE:
Have started working without any changes from my side.
There are many bugs in Drive that can cause hard 500 errors, and also many transient internal scenarios (esp. timeouts) that can cause them. It's important that you do as much research as possible so you can distinguish between the two, since some are permanent whereas others may succeed after a backoff and retry.
In your case, I suspect you are tripping over the infrastructure issues that Google have confirmed have been affecting Drive (and perhaps other services) over the last few days. See https://plus.google.com/106160348960403302854/posts/CwH9SEDTQ4C

Web Security Membership & Database Permissions

I am trying to deploy my site to 123reg but having difficulty with database permissions. I see other people have similar issues, but they all seem to be using entity framework with DBContexts, whereas I am not (I don't think).
I am using the Web.Security.Membership.CreateUser method. All of the database tables are set up. My connectionstring is almost certainly correct as I have the same setup on a different hosting provider which works perfectly. The site can read from the database but fails when it tries to write.
When the method is invoked, I get the following error.
CREATE DATABASE permission denied in database 'master'.
Is there anyway to stop the DefaultMembershipProvider from trying to create the database or tell it exactly where it is?
<add name="Simple.Data.Properties.Settings.DefaultConnectionString" connectionString="Server=ATLAS-SQL-07;Database=mydatabasename;User ID=myuserid;Password=xxxxxx;" />
I'm using Simple.Data (as can be seen the from name of the connectionstring). Maybe this is causing it problems. I don't see why it works flawlessly on my Netcetera hosting though?
To test it out further, I published the MVC4 sample web application to 123reg and pointed to the same database, it had exactly the same issue.
I had a similar problem with 123-reg; and a number of other issues. I found the best approach
was to blank out the call to create database and import a working database, (with one user in it). Make sure you do the import file as ANSI, otherwise you get a random character inserted on the import.
private class SimpleMembershipInitializer
{
public SimpleMembershipInitializer()
{
Database.SetInitializer(null);
try
{
/*
using (var context = new UsersContext())
{
if (!context.Database.Exists())
{
// Create the SimpleMembership database without Entity Framework migration schema
((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
}
}*/
WebSecurity.InitializeDatabaseConnection("TobaContext", "UserProfile", "UserId", "UserName", autoCreateTables: true);
}
catch (Exception ex)
{
throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
}
}
}
I have had a number of problems with 123-reg - some of it my fault - some of it theirs I think.
As a heads up on membership - at the moment I am getting problems with the RequireHTTPS attribute. It appears to cause a
'too many server redirects' issue. Yet I thought that attribute was suppose to work out of the box.
Good luck, hope been of some help,
Dave

Resources