I suspect someone would have used database caching somewhere before in some other asp.net project. Further, I suspect a specific database would have been created for the caching needs too. My goal is to re-use what is already there: I need find the connection string to that database and let my asp.net application cache to the same database. Is there anyway I can find tables related to sql server object caching?
ASP.NET caches in memory not to database by default. It's only user sessions that can be configured to use the database. Any reason for wanting a database implementation of caching (database introduces performance overhead)?
Here's some info on writing an output cache provider in .NET 4.0.
Related
I have been reading all over the place about the new MemoryCache class starting in .Net Framework 4.0. From what I've read, you can access the MemoryCache across different .Net applications. I am trying to share an object between an Asp.Net application and a standard windows forms .Net application. If I add the object to the MemoryCache in the .Net application, the Asp.Net application does not see it. Is there any way to accomplish this? Thank you for your time, it is greatly appreciated.
Windows Form App:
Dim cache As ObjectCache = MemoryCache.Default
Dim policy As New CacheItemPolicy()
policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(60)
cache.Set("testcache", TestObj, policy)
Asp.Net App:
Dim cache As ObjectCache = MemoryCache.Default
If IsNothing(cache("testcache")) Then Response.Write("TestCache Is Nothing")
Thanks -
Ryan
No, that's not possible. MemoryCache is not a distributed caching solution. So it will only be available locally.
If you are looking for a distributed cache alternative you may want to look into AppFabric or Redis.
However, it does sound a bit like an odd architecture to want to share the cache that way.
Maybe exposing a shared services layer, that both the asp.net and winforms consume, and have just the services implement the caching would seem more logical (take into account I actually know nothing about the problem you are trying to solve, so I could be wrong).
Caching is more commonly used for performance reasons, not as a way to share data among applications.
MySQL memory tables are working great and having stellar performance. 20/30 inserts a second and only around 1% CPU load.
I realize this advice is not timely, but for others reading this question, another possibility is Interprocess Communication (IPC) between the two programs. This way the two programs can exchange messages/data directly without going thru an intermediate.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574(v=vs.85).aspx
From the documentation above, here are some of your options.
Clipboard
COM
Data Copy
DDE
File Mapping
Mailslots
Pipes
RPC
Windows Sockets
In your case, mapped memory files might be the best approach as it allows for a shared memory space between applications. Fundamentally, your MySql/Redis approach is probably not that different.
if you are interested in :
single server multiple applications - memory share
you should consider create web api at the same node and consume it (simple key value API)
and use simple Memory Cache provided by .net framework
multiple servers - memory share
free $$ solution
you can use "Distributed SQL Server Cache", allows the
distributed cache to use a SQL Server database as its backing store.
To create a SQL Server cached item table in a SQL Server instance,
you can use the sql-cache tool. The tool creates a table with the
name and schema that you specify.
if you have a cluster of nodes you can use NCache it is
an open source in-memory distributed cache developed natively in
.NET and .NET Core. NCache works both locally and configured as a
distributed cache cluster for an ASP.NET Core app running in Azure
or on other hosting platforms.
solutions that require paying money:
NCache mentioned previously, there's Professional and Enterprise solutions,
or
Redis Cache - Redis is an open-source in-memory data store, which is often used as a distributed cache. You can configure an Azure Redis Cache for an Azure-hosted ASP.NET Core app, and use an Azure Redis Cache for local development.
This is my first foray into building a secure web application. It will be on the internet, and it comprises an IIS server (hosted by ISP) and SQL 2008 db (Also hosted by ISP.
As a quick and dirty test I am just using the template in Visual Studio. I have configured authentication by just using the wizard on the ASP.NET configuration tool. However, this creates a database that is hidden within the web app.
I would prefer to keep the user credentials on the SQL server, as it seems like best practice to allow for scalability. However, how do I do this? I have limited access to the database - I can create tables, but don't think I'll be able to run any tools on the server to create the right schema. Can anyone point me in the right direction? Done some googling, but keep seeing ASP.NET 1.1 articles, which makes me think I may be missing something, and there is a better way of doing this in ASP.NET 4.0.
Create a User table in SQL Server that stores user login and password. You can hash the password so that it's not visible even to admins themselves including yourself. Then using LINQ to pull during form authentication to check login name/password against the User table.
You can also use embedded SQL or stored procedure in place of LINQ. However, embdedded SQL is highly unsafe so that leaves stored procedure and Linq. I would prefer using Linq if you are familiar with it. Or using stored procedure which is always the safest.
You don't "have to" use the entire ASP.Net Membership framework to use Forms Authentication. It does a lot of the plumbing for you (security, etc), so if you can, it's probably best you use it - more so, if you're getting started.
You can use Forms Authentication with any auth scheme you want (pre-existing or something you create yourself). Here's an overly simplistic sample where you can see that you can even hard-code the auth scheme (not that you should, but it shows you the possibilities).
Lastly, if you can't run the command line ASP.Net tool aspnet_regsql.exe, the sql scripts to create the schema are in: C:\Windows\Microsoft.NET\Framework\[Framework version].
So for .Net 4, it would be: C:\Windows\Microsoft.NET\Framework\v4.0.30319
Both install and "uninstall" sql scripts are there - e.g.
InstallMembership.sql
UninstallMembership.sql
... and so on....
I need to quickly wrap some security around an existing ASP.Net 2.0 web app. After thinking about it for a moment, I remembered that Microsoft created that Membership and Roles paradigm a couple of years back, and that Visual Studio could essentially create everything for you.
Thus I forged forward using the built in ASP.Net Web Site Administration Tool and created a simple little security framework around the application. After setting all of the options, Visual Studio created a nice little SQL Express DB called ASPNETDB.MDF right under the newly created App_Data directory of my website. This works great until you deploy it.
After trying to push this app to my DEV server I realized that it's not going to work unless you have SQL Express installed on the hosting machine. Worse yet, I figured that there's essentially no way this would work under a load balanced environment considering the DB itself will only be isolated to one of the N nodes.
Rather than work to script out the DB and shove it into my existing SQL box...I figured I'd ask the StackOverflow if there is a better solution for simple yet secure ASP.Net websites.
I'd love to maintain the existing model yet have the database become a local, or flat-file DB baked right into the application. For the time being I'm even fine with deploying the flat file with each user or role change to counteract the load balanced sites in PROD.
Is there not a way to create some sort of similar setup with a flat file? I thought that was the point of the App_Data folder?
You could use a custom Role & Membership provider that supports a flat file, like XML. Here is a link to a XML Membership provider, I've seen similar implementations for Roles.
XML Membership Provider
it's not going to work unless you have SQL Express installed on the hosting machine.
Not necessarily. If you still want to use default membership/role providers you can either have the DB server on the hosting machine or have one instance of the DB as a separate server (just change the connection string for providers).
Worse yet, I figured that there's essentially no way this would work under a load balanced environment considering the DB itself will only be isolated to one of the N nodes.
This statement is not really correct in this particular situation.
With load-balancing you will not have isolated database, but rather a separate database server.
I'd love to maintain the existing
model yet have the database become a local, or flat-file DB baked right
into the application. For the time
being I'm even fine with deploying the
flat file with each user or role
change to counteract the load balanced
sites in PROD
If you say that application with proper SQL DB will not scale, I do not understand how flat-file storage can.
You still can keep local SQL Server database and it will work as long as you take responsibility of maintaining the database consistency across different nodes.
In your situation, I would personally use default membership/roles provider as you do now.
But when deploying, just change the connection string to the proper database server.
You will need a database for other stuff anyway, so why not use the same database for all data withing the application (including membership/roles).
Regards.
I found an excellent solution to this here...http://aspnetxmlproviders.codeplex.com/. Using the dynamic XML you can hack out a simple provider based security model in no time flat.
I've a question regarding SqlCacheDependency configuration. Every resource I've read requires the developer to define the polled databases into web.config.
This is not a good scenario for our application that connects to different databases, because we don't want to edit web.config each time we add / remove a database.
We tried to configure it using SqlCacheDependency and SqlCacheDependencyAdmin in application startup but it seems that you must anyway configure everything in web.config.
Do you know a possible solution?
Thanks,
Marco
We're planning to use standard ASP.NET user authentication for our application. However, by default this requires us to have our user database on our web server in the App_Data folder.
This is usually a big no-no for us - our databases are all behind the firewall and all access is done via a WCF Service layer.
If the database was on a different server, but directly accessible from the web server then this still vioates our usual architecture rules.
Should we worry about our user database living on our web server? Does ASP.NET offer an out-of-the-box alternative?
NOTE: We're using .NET 3.5 and SQL Server 2005
You can install the neccessary db tables etc. in any SQL Server database.
Use the aspnet_regsql.exe Wizard found in C:\WINDOWS\Microsoft.NET\Framework....... to set up the target database.
Then simply update the connection strings in the provider configurations in the web.config.
Yes and Yes.
If you ever need to move to multiple web servers you shouldn't have the user data on one of those servers.
There are multiple was to do this, but check out this link for details on one MSDN How To: Use Forms Authentication with SQL Server in ASP.NET 2.0
you can create your own Custom membership provider by overriding the methods and properties of the following abstract class: public abstract class MembershipProvider. Once you override them, then you can use any valid datasource to authenticate the user. For example, you can use MYSQL, SQL server or even XML file to authticate your users. These provider models are really really cool.
Yes, you should worry. No, there is no out-of-the-box solution. ASP.NET only ships with a SQL Membership Provider and an Active Directory membership provider (reference). You will have to use a custom membership provider to provide your functionality.