Monday, November 16, 2009
Speech server application and Cache
In the speech server application I am creating, I need to load some data and save it into the Cache so every call can share that data in a readonly fashion. The normal way for me to access Cache is to use HttpContext.Current.Cache. However, HttpContext.Current is null in speech server application. I tested in both IIS 5.1 and 6.0 with soft and regular land phone. I then began to use WorkFlow.UserData as the application Cache. It works fine except you can't set its expiration time. After a little research and I found that I can acutally access Cache by HttpRuntime.Cache, and it even performance a little better. A good article to compare these two different way of accessing Cache is here.
Friday, November 13, 2009
speech server running under iis 5.1
It seems like the speech server is only designed to run under iis 6.1 or higher. According to this reference: It "Setup program creates an application pool called Speech Server under which Speech Server applications are intended to run". and by default "The Speech Server processes run as the NETWORK SERVICE account". It should use this default account when accessing local resource and use current windows account to access network resource (such as database and shared file server).
However, the IIS 5.1 doesn't have application pool and web app running under 5.1 is using [machinename]/ASPNET user account by default. It's uncertain if speech server has issue to use this account to access local resource, but it definitively failed to use local windows account when accessing network resource under IIS 5.1. The error developer will see is like: Login failed for user ''. The user is not associated with a trusted SQL Server connection. Please note the user account here is a empty string.
Solution is to updateto force impersonation in the machine.config under the currently used .NET framework folder. An example would be like this:
<processmodel password="[password]" username="[domain]\[username]">
here are some other good references helped me regarding this issue:
Understanding ASP.NET Impersonation Security
processModel Element (ASP.NET Settings Schema)
However, the IIS 5.1 doesn't have application pool and web app running under 5.1 is using [machinename]/ASPNET user account by default. It's uncertain if speech server has issue to use this account to access local resource, but it definitively failed to use local windows account when accessing network resource under IIS 5.1. The error developer will see is like: Login failed for user ''. The user is not associated with a trusted SQL Server connection. Please note the user account here is a empty string.
Solution is to update
<processmodel password="[password]" username="[domain]\[username]">
here are some other good references helped me regarding this issue:
Understanding ASP.NET Impersonation Security
processModel Element (ASP.NET Settings Schema)
Wednesday, May 27, 2009
list<> sort or order using limbda expression
If doing an in-place sort (i.e. the list is updated):
people.Sort((x, y) => string.Compare(x.LastName, y.LastName));
If need to create a new list:
var newList = people.OrderBy(x=>x.LastName)
Springboard example, sorting sections on section No.
List sections = new List();
//... load sections ...
sections.Sort((x, y) => x.SectionNo.CompareTo(y.SectionNo));
people.Sort((x, y) => string.Compare(x.LastName, y.LastName));
If need to create a new list:
var newList = people.OrderBy(x=>x.LastName)
Springboard example, sorting sections on section No.
List
//... load sections ...
sections.Sort((x, y) => x.SectionNo.CompareTo(y.SectionNo));
insert from selecting from another database
In one case, I need to import data from one database to another database, and I've figured out the format should be
insert into server.newdatabase.owner.table
from select * from server.olddatabase.owner.table
the key point here is the four parts name follows the pattern server.database.owner.object
insert into server.newdatabase.owner.table
from select * from server.olddatabase.owner.table
the key point here is the four parts name follows the pattern server.database.owner.object
Monday, April 20, 2009
using delegate in sorting generic list
1: List<Article> allArticles = GetAllArticles();2: allArticles.Sort(delegate(Article x, Article y) { return DateTime.Compare(x.LiveDate, y.LiveDate); });
Friday, April 17, 2009
sharing content between different sites
Constantly we are facing some issues when sharing content of site A with site B. Normally the content to be shared is header/footer, and they are user controls at site A. On the other hand, site B wants an easy yet reliable way to access the content and automatically updated content without changing anything on its own side. During past years of building application to solve this problem, I think these two designs are both good solutions:
Design A
Design B at site B:
Design A
- site A wrap the user control into web service
- site B call web service to get html content
- site B implement both memory cache and cache file to fail back on in case web service call failed. when failing, it trys to load from memory cache first, if there is no content in memory cache, then load it from cache file. when next time a web service call is successful, update memory cache and cache file
pro of Design A:
- very reliable as both memory cache and cache file are available for fall back
cons if Design A:
- site A need to be careful in implementing user control, can't assume some page information like session is available is httprequest
- complex logic in site B to implement fall back workflow
Design B
- Site A wrap user control in a regular aspx page, using javascript document.write to emit content
- Site B consume content by reference to this page as a javascript source
pro of design B:
- easy to implemet on both sides
cons of design B
- no fallback logic, when site A is done, it screw up site B as well
Both wraping solution can't solve the issue if the content need to post back to itself after submit. For example, if a user control has some code behind logic after submit, it won't be available in both wrapped version.
Source code:
Design A at Site A:
HeaderControl hc = (HeaderControl)p.LoadControl("~/UserControls/" + ControlName);Design B at site A:
hc.IsSecure = IsSecure;
hc.IsOLSMenu = true;
hc.Page_Load(null, null); //call page_load to load mennu
hc.RenderControl(htmlWriter);
StringWriter sw = new StringWriter();
Page p = new Page();
HtmlForm f = new HtmlForm();
p.Controls.Add(f);
Header h = (Header)p.LoadControl("~/controls/header.ascx");
p.Controls[0].Controls.Add(h);
Server.Execute(p, sw, false);
Design B at site B:
<script language="javascript" src="http://ta-homecorporate.progressive.com/scripts/headerwrapperjs.aspx"></script>
Subscribe to:
Posts (Atom)