Archive for the ASP.NET Category

Useful Visual Studio 2010 Extensions

Tuesday, July 20th, 2010

Scott Dorman posted a handy list of his Favorite Visual Studio 2010 Extensions.  It is definitely worth checking out and is a good place to start after installing VS 2010.  So far, I have downloaded several of them.

Tags: ,

Auto Indent Visual Studio 2010 Code With Ctrl-K-F

Tuesday, July 20th, 2010

In Visual Studio 2010, hitting Ctrl-K, Ctrl-F will auto indent a highlighted section.  Ctrl-A, Ctrl-F Ctrl-F will do the whole file.

Tags: , , , , ,

Intel says their server diagnostics have limited support for servers with web pages

Wednesday, April 28th, 2010

What the heck is he talking about you ask?  I was recently told by Intel Server support, that they do not support (or intend to support) using the Intel server diagnostics (Intel® Active System Console) on servers that provide a website using forms authentication (a really common type of login authentication).  I was told that their tools only work if you use ASP.NET authentication on the primary website on your server.

My understanding from them was that if  you authenticate against another database (which many pages do), then you can not check the status of the hardware on your Intel server.  WTF?

Over a year ago, we bought a couple of big Intel servers for a new website that our company was launching.  After several issues getting the hardware delivered, we were finally up and running.  Then, our hardware guy decided to check on the status of the RAID and things went downhill rapidly.

The tools that Intel provides to check the RAID, redundant power supply etc, just generated errors when we tried to start them up.  We spent a lot of time talking to support about this and getting stupid suggestions like “reload all the software” or “reinstall the OS”.  Finally, we had to actually take the machine apart in order to get ALL of the part numbers so that they would escilate the issue.  Apparently it had never occured to them that we might want to use this for a production server where we need it to reliably run 24/7 and not be taken down and taken apart to address unrelated software issues.  I begged and pleeded, but they would not escilate our software issue unless we did this!

After that, there were more delays.  Some days I would get told that they had replicated the issue and were working on it, other days they somehow could not replicate the issue.  This was pretty baffling since it is really simple to replicate and we had been told that they had gotten that far.  Then they returned to suggestions like “try reinstalling the OS and see what happens”.  Did I mention that this was the production server?

Eventually it came out that they assume that  you have a default website set up with the default ASP.NET authentication.  I was told that they do not support any other setup.  This is from what I thought was a serious sever!?

The last email that I got (7/31/2009, now I just get an automatic response when I email) said:

Hello Mark,

We have been informed by engineering that they have not been able to reproduce or fix the issue you are experiencing with your own form authentication. The only recommendation we have at this point is for you to uninstall the Intel® Active System Console completely, install its standard pre-requirements and use the software in the normal way it was intend to be used. If this is not suitable for you then you will not be able to use this software at this point.
Engineering at this point says that the only fact is that your authentication method will not work with the Intel® Active System Console 3.5.1, and the only other option would be for you to provide us with a copy of the software you use on this server and detailed information about the setup and the environment for us to try a more accurate reproduction.

Sincerely,

Jorge S
Intel Technical Support

Maybe I read it wrong, but it looks to me like it says “we can not reproduce the error, but we know that it will only work with authentication method that we intend you to use on your server”.  Seriously?  This is a server, but I can not use it to serve a website?

I have not heard from them since and since then, they don’t even bother to answer emails…

Needless to say, until Intel starts to support what they sell, we have stopped purchasing their equipment.

If anyone at Intel wants to explain this better, it is case number 8969057…

Tags: , , , , ,

How to get Session Parameters in an ASP.NET ASMX service.

Monday, April 12th, 2010

Session parameters get used a lot in ASP.NET pages and they work pretty well, but when you try to use them in an ASMX web service, you get errors.  So, how do you get the session parameters?

It turns out that it is really simple.  Just add “EnableSession = true” to your WebMethod and it all works as expected.  For example:

[WebMethod (Description="Get a list of RMU GPS positions as JSON for the current custId.",
    EnableSession = true)]
public string GetSomeData()
{
    string  custId = "0";
    try
    {
        custId = Session["CustId"].ToString();
        return(GetSomeDataFromClientId( CustId );
    }
    catch (Exception ex)
    {
        handleException(ex, "GetGpsRmuCustListJSON");
        return(some failure message...);
    }
}

Tags: , , , ,

Parser Error Message: Could not load file or assembly ‘VJSharpCodeProvider

Friday, April 9th, 2010

I have been working on an ASP.NET website for quite a while and recently went to flip it onto a different server for testing.  Like many before me, I was pretty baffled when I got a configuration error claiming that I needed the VJSharpCodeProvider.  I don’t even use Visual J Sharp.

Further research came up with the fact that if your project uses Java, then Microsoft will kindly add this in for you.  I just went into the web.config file and deleted the assembly reference to VJSharpCodeProvider and everything was happy.

The error page looked like:

Server Error in ‘/’ Application.


Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load file or assembly ‘VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified.

Source Error:

Line 89: 		<compilation debug="true" strict="false" explicit="true">
Line 90: 			<assemblies>
Line 91: 				<add assembly="VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
Line 92: 				<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
Line 93: 				<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>


Source File: C:\corView\WebSite\web.config Line: 91

Assembly Load Trace: The following information can be helpful to determine why the assembly ‘VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ could not be loaded.

=== Pre-bind state information ===
LOG: User = NT AUTHORITY\NETWORK SERVICE
LOG: DisplayName = VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/corView/WebSite/
LOG: Initial PrivatePath = C:\corView\WebSite\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\corView\WebSite\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: The same bind was seen before, and was failed with hr = 0x80070002.


Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3601

Tags: , , ,

Google Maps Fail to Display on IE6

Friday, March 26th, 2010

I have a website that I work with that uses Google Maps to display some markers on a map for the user.  It works great in the office.  We tried Firefox, IE6, IE7, IE8…  All good.

Now I have a couple of users who all say that the maps do not display when they try to use them on the company networks.  To make it worse, these companies all require users to use IE6 “because it is proven.”  What a pain.

Has anyone else had issues showing Google Maps on corporate networks?

We have tried the suggestions in the Google article “Issues While Using Internet Explorer“, the Microsoft article “How to troubleshoot script errors in Internet Explorer on Windows-based computers” and a useful post on EasyPagez.

The biggest issue of course seems to be figuring out what the corporate settings for IE6 actually are…

Tags: , , ,

Delphi Prism 2010 Does Not Seem To Use Subdirectories

Friday, March 5th, 2010

When working on an ASP.NET website, I find it a lot easier if you put related sections in seperate subdirectories.  For example:

CSS and Javascript can be put in a directory with caching in order to speed up the page loads

Pages that are only available to certain roles (i.e. “Admin”) can be put in a seperate directory and then you set the web.config so that only that role can access the directory.  This helps to make it really clear who the page is ment for.

While attempting to port a site from Delphi RAD 2007 to Delphi Prism 2010, I was amazed that it would not let me do this.  I even opened a site in Visual Web Developer 2008 (the Microsoft compeditor that Prism basically uses as the IDE) to check if it was a Microsoft issue.  Not only did the Microsoft Web Developer 2008 allow it, but when I went to create a code file, it suggested putting it into app_code and offered to move it there for me (but did not force me to if I didn’t want to).

In comparison, in Delphi Prism 2010, I opened {project}\css\proj.css.  Instead of allowing me to use the file where it was, Prism created a brand new file {project}\proj.css and added that to the project.  To add to the confusion, it left the old file {project}\css\proj.css.  Now I have two copies of proj.css.  I tried it with several different files and kept having this issue.

Not only is this annoying, I find that this really makes a larger site a lot harder to maintain.

Tags: , ,

Accessing Firebird from Delphi Prism 2010.

Tuesday, March 2nd, 2010

Here is a quick routine to read values from a Firebird Database into Delphi Prism.

uses FirebirdSql.Data.FirebirdClient;

method  RunSqlCmd(sqlCmd: string; resultName: string; var FieldVar: array of string; FieldName: array of string): string;
var
conStr:     string;
count:      integer;
i,j:        Integer;
colName:    string;
val:        string;
dataType:   System.Type;
dataTypeStr: String;
fbConn:     FbConnection;
fbTran:     FbTransaction;
fbReader:   FBDataReader;
fbCmd:      FbCommand;
begin
count:=WebConfigurationManager.ConnectionStrings.Count;
if(count>0)then
begin
conStr := WebConfigurationManager.ConnectionStrings['RMU'].ConnectionString;
end;
fbConn := new FbConnection(conStr);
fbConn.Open;
fbTran := fbConn.BeginTransaction();
fbCmd := new FbCommand(sqlCmd, FbConn, fbTran);
fbReader := fbCmd.ExecuteReader();
if (fbReader.Read()) then
try
for i := 0 to fbReader.VisibleFieldCount – 1 do
begin
colName := fbReader.GetName(i).ToUpper; //PRISM  GetDataTypeName  ValueType[i].Name.ToUpper();
dataTypeStr := fbReader.GetDataTypeName(i);
dataType := fbReader.GetFieldType(i);
try
if (dataType = typeof(String) ) then
val := fbReader.GetString(i).ToString
else
if (dataType = typeof(Int16)) then
val := fbReader.GetInt16(i).ToString
else
if (dataType = typeof(Int32)) then
val := fbReader.GetInt32(i).ToString
else
if (dataType = typeof(Double)) then
val := fbReader.GetDouble(i).ToString
else
if (dataType = typeof(DateTime)) then
val := fbReader.GetDateTime(i).ToString
else
val := ”;
except;
val := ”;
end;
if ((colName = resultName.ToUpper()) and (resultName <> ”)) then
result := val
else
begin
for j := Low(FieldName) to High(FieldName) do
begin
if ((colName = FieldName[j].ToUpper()) and (FieldName[j] <> ”)) then
begin
FieldVar[j] := val;
break;
end;
end;
end;
end;
except
end;
fbReader.Close;
FbConn.Close;
end;
To call it, you have a function like:
method RunSqlSelect(someParam: string);
var
custId:          string;
usrFullName:     string;
usrAccessLevel:  string;
userActive:      string;
sqlStr:          string;
results:         stringArray;
recMask: integer;
bondMask: integer;
testMask: integer;
allMask:         integer;
begin
results := new stringArray(19);
sqlStr := ‘SELECT USR_CUST_ID, USR_ID,C_TEMP_DISPLAY,USR_FIRST_NAME,USR_LAST_NAME’ +
‘  from GET_USER_INFO_R02 (”’ + userName + ”’) ‘;
RunSqlCmd(sqlStr, ”, results,
['USR_CUST_ID', 'USR_ID', 'C_TEMP_DISPLAY', 'USR_FIRST_NAME', 'USR_LAST_NAME',
'C_NAME', 'USR_RECTIFIER_PG_MASK', 'USR_BOND_PG_MASK', 'USR_TEST_PG_MASK',
'USR_ALL_PG_MASK', 'USR_ACTIVE', 'USR_PASSWORD_OK', 'USR_SHARED_MASK', 'EMAIL',
'TZ_OLSON_NAME', 'USR_REPORTS_IN_UTC', 'TZ_SHORT_DESC', 'RPT_TZ_OLSON_NAME',
'RPT_TZ_NAME_FULL']);
usrFullName := results[3] + ‘ ‘ + results[4];
custId := results[0];
//blaaa, blaa, blaaa…
end;

Tags: , , ,

Finding the PublicKeyToken of a dll with .NET

Friday, February 26th, 2010

Here is a quick and easy way to find the PublicKeyToken of a dll using the Glabal Assembly Cache (GAC).

  1. In the command prompt, go to the folder with your dll.
  2. Install the dll in your GAC using gacutil.exe -i <assemblyName.dll>
  3. View the assembly info using gacutil.exe -l <assemblyName>
  4. If you do not want the assembly left in the GAC, remove it with gacutil.exe -u <assemblyName>

Another way to do it is to use sn.exe -T <assemblyName.dll>.  This only works if the assembly is strongly signed.

Tags: , , ,

For Delphi 2007 RAD ASP.NET development, Borland.Data.AdoDbxClient

Thursday, September 10th, 2009

I have been doing quite a bit of ASP.NET development using Delphi 2007 RAD. After a lot of testing, it looks like the Borland.Data.AdoDbxClient leaks quite badly (i.e. on XP aspnet_wp.exe and on Win Server 2003 w3wp.exe uses more and more memory until it fails). First of all, a huge thanks to Felix John COLIBRI for his very useful articles:

  • http://www.felix-colibri.com/papers/web/asp_net/delphi_asp_net_20_databases/delphi_asp_net_20_databases.html
  • http://www.felix-colibri.com/papers/db/delphi_dbx4_programming/delphi_dbx4_programming.html

Much of my test code is taken almost directly from him. If I set up my datasource as:

runat=”server”
connectionstring=”<%$ ConnectionStrings:RMU %>” providername=”FirebirdSql.Data.FirebirdClient” cacheduration=”1″ cacheexpirationpolicy=”Sliding” selectcommand=”SELECT * FROM GET_MSG_CMD_LIST(?,?,?)”>

Then it seems to run quite well. If I switch the providername to use Borland.Data.AdoDbxClient, then it chews through memory quite quickly. I also found that the following procedure leaks about 4k every time you run it:

procedure RunSql(sqlCmd: string); var

count: integer; dbxConn: TAdoDbxConnection; dbxCmd: TAdoDbxCommand; conStr: string;

begin

count:=WebConfigurationManager.ConnectionStrings.Count; if(count>0)then

conStr:=WebConfigurationManager.ConnectionStrings['RMU_db'].ConnectionString;

dbxConn := TAdoDbxConnection.Create(conStr); dbxCmd := TAdoDbxCommand.create; dbxCmd.Connection := dbxConn ; dbxCmd.CommandText := sqlCmd; dbxCmd.Connection.Open; dbxCmd.ExecuteNonQuery; dbxCmd.Connection.Close; dbxCmd.Dispose; dbxConn.Dispose;

end;

However this works just fine:

const ConnectionName=’RMU-ini’; procedure RunSql(sqlCmd: string); var

count: integer; Conn: TDbxConnection; Cmd: TDbxCommand; ConnectionFactory: TDBXConnectionFactory; Properties: TDBXProperties;

begin

ConnectionFactory:= TDBXConnectionFactory.GetConnectionFactory; Properties:= ConnectionFactory.GetConnectionProperties(ConnectionName); Conn:= ConnectionFactory.GetConnection(Properties ); Cmd:= Conn.CreateCommand; Cmd.Text:= sqlCmd; cmd.ExecuteUpdate; Cmd.free; Conn.free;
end;

And this also works fine:

procedure RunSql(sqlCmd: string); var

count: integer; dbConn: DbConnection; dbCmd: DbCommand; dbTrans: DbTransaction; conStr: string; dbFactory: DbProviderFactory; dbDA: DbDataAdapter;

begin

count:=WebConfigurationManager.ConnectionStrings.Count; if(count>0)then

conStr:=WebConfigurationManager.ConnectionStrings['RMU'].ConnectionString

else begin

{ TODO 5 : Add an error handler here. This of course should never happen!} exit;

end; dbFactory:=DbProviderFactories.GetFactory(‘FirebirdSql.Data.FirebirdClient’); dbConn := dbFactory.CreateConnection; dbConn.ConnectionString := conStr; dbCmd := dbConn.CreateCommand(); dbCmd.CommandText := sqlCmd; dbConn.Open; dbCmd.ExecuteNonQuery; dbConn.Close; dbCmd.Dispose; dbConn.Dispose; end;

Well, I hope this helps!
This was posted on the CodeGear Delphi site at: https://forums.codegear.com/post!reply.jspa?messageID=20685

Tags: ,