Posts Tagged ‘.NET’

Error ‘String cannot have zero length’ when install ASP.NET starter kit

Sunday, January 24th, 2010

Sometimes when you download the .vsi starter kit installer file , you might get the following error message:

A problem occurred while running the installer. Please contact the content author for problems with the content.
Error Message:
Strings cannot have zero length.

The reason is because you might had installed Visual Studio 2005 and VWD 2005 Express , but later you uninstalled one of the two (for example you uninstall VWD 2005 Express) and a couple string values got deleted in the registry. 

Solution:

Try the following to see if it works for you:

   1.Click START then RUN then type REGEDIT and Enter.
   2. Go to this location on the registry: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSEnvCommunityContent\ContentTypes\VSTemplate]
   3. On the right side of the screen right click –> New –> String Value and add the following two string values

 Value Name = “ClassName”    Value Data = “VSContentInstaller.VSTemplateInstallerPage”
 Value Name=  “DisplayName”  Value Data = “#VSTemplateContentDisplayName”

Close the registry and try to install .vsi starter kit again, it should work.

Installing Sitefinity using Blank Project without IIS

Sunday, January 17th, 2010

How to use Sitefinity if you don’t want to install IIS or your IIS doesn’t work well ?

You aren’t required to run the Sitefinity install.  Sitefinity is also distributed via a blank project zip file.  This empty Sitefinity project can be opened in Visual Studio and does not require IIS.

Please read a guide here: Installing Sitefinity using Blank Project

Install SiteFinity on Vista or Windows 7

Sunday, January 17th, 2010

 Bullet Proof Guide to Installing Sitefinity 3.x

– content from sitefinitywatch.com

If you wanto to install Sitefinity on your local machine.  Because Sitefinity is intended to be a server product, installing on an non-server computer can be challenging.

Above link provided a video & blog which describe to  designed to be a guide to installing Sitefinity on Windows Vista and/or Windows 7.  If you’re running Windows XP, you’ll find the Sitefinity install to be less challenging because XP uses IIS6 and the OS security isn’t as limiting.

Note: You aren’t required to run the Sitefinity install.  Sitefinity is also distributed via a blank project zip file.  This empty Sitefinity project can be opened in Visual Studio and does not require IIS.

IIS: The service did not respond to the start or control request in a timely fashion

Saturday, January 16th, 2010

After we installed IIS 5 or IIS 6 in Windows XP pro SP2, we might get the following error message when we try to start IIS service.

“The service did not respond to the start or control request in a timely fashion.”

One of the reason is because that you might have installed ASP.NET 2.0 or 3.5 before you installed IIS. The simple way to resolve it is just re-install ASP.NET by a one-line command, for example:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis -I -enable

Then done, you can start your IIS now.

The further more relevant information you might read here (David Wang), I never read his article since I just restart my ASP.NET, I just copied the content here for reference:

HOWTO: Diagnose one cause of W3SVC failing to start with Win32 Error 193 on 64bit Windows

I recently came across an interesting new variation of “failure” related to enabling WOW64 that can happen on IIS6 on 64bit Windows… so I am going to explain what happened and how to fix it.
Question:

Hi,

I ran into an issue with IIS in wow64 mode. On this machine I consistently get an error trying to turn on wow64 mode.

I turn on wow64 mode in IIS, do IISReset, and then when I run “aspnet_regiis –I –enable” from the 32-bit directory, I get an error in the log file:

2005-12-14 12:37:39     Failure     Waiting for service to start: WaitForServiceState failed with HRESULT 8007041d: ‘The service did not respond to the start or control request in a timely fashion. ‘
2005-12-14 12:37:40     Failure     Starting service: w3svc: StartServiceByName failed with HRESULT 8007041d: ‘The service did not respond to the start or control request in a timely fashion. ‘
2005-12-14 12:37:40     Failure     Restarting W3SVC: RestartW3svc failed with HRESULT 8007041d: ‘The service did not respond to the start or control request in a timely fashion. ‘

If I check the w3svc service, it is stopped. If I try to start it, I get:

The World Wide Web Publishing Service service is starting.
The World Wide Web Publishing Service service could not be started.

A system error has occurred.

System error 193 has occurred.

*** is not a valid Win32 application.

If I check the EventVwr, I get:

Could not load all ISAPI filters for site/service. Therefore startup aborted.

ISAPI Filter ‘d:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_filter.dll’ could not be loaded due to a configuration problem. The current configuration only supports loading images built for a AMD64 processor architecture. The data field contains the error number. To learn more about this issue, including how to troubleshooting this kind of processor architecture mismatch error, see http://go.microsoft.com/fwlink/?LinkId=29349.

This error makes no sense to me, because at this point IIS is in wow64 mode, so it should not have any problems loading the 32-bit aspnet_filter.dll.

I double-checked that wow64 mode is turned on:

Enable32BitAppOnWin64           : (BOOLEAN) True

Do you know what could be causing this?
Answer:

Hmm… this issue is indeed interesting because all the rules for running IIS6 in WOW64 mode, as explained in this blog entry, were obeyed… except for one little detail that I did not mention earlier, though it is definitely there in MSDN documentation:

    WOW64 mode is only valid when IIS6 is running in Worker Process Isolation Mode.

In particular, WOW64 mode is not valid when IIS6 is running in IIS5 Compatibility Mode. Now, we can argue over the philosophical oxymoron where “IIS5 never existed as 64bit” and “IIS6’s IIS5 Compatibility Mode on 64bit Windows only runs as 64bit”, but let’s not sidetrack ourselves here… ;-)
The Problem…

What happened in this situation is that IIS6 is simultaneously configured to run in IIS5 Compatibility Mode (W3SVC/IIs5IsolationModeEnabled=1) AND WOW64 mode (W3SVC/AppPools/Enable32BitAppOnWin64=1). This is actually an invalid IIS configuration, but due to the sequence of configuration events, an interesting failure condition occurrs – W3SVC fails to start up due to Win32 Error 193 when it never loads the bitness-mismatched user binary. Here is what happens:

   1. IIS6 is configured to run in IIS5 Compatibility Mode (W3SVC/IIs5IsolationModeEnabled=1)
          * This means that ISAPI Filter DLLs will run inside of the inetinfo.exe process.
          * Now, inetinfo.exe is a 64bit process because it needs to read %SYSTEMROOT%\System32\inetsrv\metabase.xml for IIS configuration.
          * The reason that inetinfo.exe cannot be a 32bit process is because WOW64 FileSystemRedirection will be in effect for all non-excluded filepaths under %SYSTEMROOT%\System32 (this is an OS-level behavior). Having duplicate metabase.xml under both System32 and Syswow64 directories is simply bad design… for example, imagine change synchronization…
   2. IIS6 is then configured to run in WOW64 Mode (W3SVC/AppPools/Enable32BitAppOnWin64=1)
   3. ASPNET_REGIIS.EXE -I -Enable from the 32bit Framework directory is run, which changes W3SVC/Filters/ASP.Net_2.0.50727.42/FilterPath to load the 32bit ASP.Net ISAPI Filter DLL from %windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_filter.dll .
   4. IIS is then restarted to load the global ISAPI Filter.
   5. When W3SVC starts, it goes down two totally different initialization paths depending on whether IIS5 Compatibility Mode is enabled. In this case, it is enabled, so W3SVC communicates with the worker process core, now loaded in inetinfo.exe (instead of w3wp.exe – this is one major difference for IIS5 Compatibility Mode), to start up.
   6. Worker process core in inetinfo.exe, a 64bit process, tries to load global ISAPI Filters as a part of initialization (this is for IIS5 Compatibility Mode – global ISAPI Filters must load at service startup, unlike the demand-start of Worker Process Isolation Mode).
   7. From step #3, a 32bit aspnet_filter.dll is configured to load… into the 64bit inetinfo.exe process… which dutifully fails with Win32 error 193 (0×800700C1).
   8. Worker process core reports this error back to W3SVC and aborts startup because failure to load ISAPI Filter is a fatal failure on IIS6 (unlike on IIS5, where ISAPI Filters implementing security features can fail to load and IIS still continues).
   9. W3SVC also treats this failure as fatal and aborts. This eventually results in ExitProcess() being called, which causes SCM to report the failure to start the W3SVC service.

The Solution…

In this case, the fix is to resolve the invalid configuration of attempting to run IIS5 Isolation Mode and WOW64 simultaneously. Either choose to run in IIS5 Compatibility Mode and keep things 64bit, or run in IIS6 Worker Process Isolation Mode with WOW64. Due to the oxymoron stated earlier, I suspect that 99.9% of the time you will choose to run in IIS6 Worker Process Isolation Mode with WOW64. I mean, 64bit ISAPI Filter which requires ReadRawData is rare commodity, most likely generated by self-interest. :-)

This means that you should run the following:

    CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs SET W3SVC/IIs5IsolationModeEnabled 0
    NET STOP HttpFilter /y
    NET START W3SVC

To switch IIS6 back into Worker Process Isolation Mode, and since you already have WOW64 enabled and 32bit DLLs correctly configured, things should just work… assuming you covered all other bases regarding WOW64 and possible bitness mismatch mentioned in my prior blog entries.

//David
Filed under: ISAPI, IIS, Your Questions, HOWTO…

Cannot convert type ‘ASP.login_aspx’ to ‘System.Web.UI.WebControl’

Wednesday, July 1st, 2009

If you have used a Page that effectively uses a codebehind classname that is the same as say the Login control, that is Login, e.g. your page was called Login.aspx, then when you pre-compile (publish) the web site as an updateable web site, the aspx is retained and tries to compile against a type called Login in the code behind. It does not resolve to be that in the codebehind assembly

Try using a classname for your codebehind and defined in the inherits that does not clash with a type in System.Web, e.g. LoginPage, or qualify the class and therefore the inherits statement with a namespace, e.g. in the .aspx file:

<%@ page … inherits=”MyNameSpace.Login” %. in the code behind file:

namespace MyNameSpace

{ public partial class Login : System.Web.UI.Page

{

..

}

}

how to get aspx page username ?

Wednesday, July 1st, 2009

in vb its system.environment.username – whats the equivalent in aspx with code behind (VB) ?

——————————————————————————–

In the codebehind of your aspx code, you could use:

Page.User.Identity.Name ;

In a custom class, you could use:

HttpContext.Current.User.Identity.Name;

——————————————————————————–

thanks but niether seems to work – aspx accepts it but it does nothing!

——————————————————————————–

It depends how you would like to use it.

If you want to get the Windows username you have to make sure you disabled anonymous access in IIS.

If you use forms authentication you can make a custom principal:
System.Security.Principal.GenericIdentity identity = new
System.Security.Principal.GenericIdentity(”testUse rName”);
System.Security.Principal.GenericPrincipal principal = new
System.Security.Principal.GenericPrincipal(identit y,new string[]{“TestRole”});

Context.User = principal;

ASP.NET: how to get page name, visiting user name, function name, form name

Wednesday, July 1st, 2009

1: string username = Me.Page.User.Identity.Name
2: string username = System.Environment.UserName()

1: string pagename = Me.Page.GetType().Name()
2: string pagename = Request.Path.Substring(Request.ApplicationPath.Length + 1)

1: string functionname = System.Reflection.MethodBase.GetCurrentMethod().Name

1: string formname = Request.Path.Substring(Request.Path.LastIndexOf(”/”)+1);

How To Create an ASP.NET Application from Multiple Projects for Team Development

Wednesday, July 1st, 2009

How To Create an ASP.NET Application from Multiple Projects for Team Development

A nice article from Microsoft:

How To Create an ASP.NET Application from Multiple Projects for Team Development

(from: http://support.microsoft.com/kb/307467)

Here just copy their Summary and give the left to redirect their site. 

SUMMARY

loadTOCNode(1, ’summary’); This article describes how to make multiple ASP.NET projects participate in the same Web application.

You may find it useful to separate a large Web application project into multiple projects for team development of ASP.NET Web applications in Microsoft Visual Studio .NET. Microsoft recommends that you use source control software, such as Microsoft Visual SourceSafe, in all scenarios.

Developing a large Web site frequently involves several developers. These developers must be able to work on specific sections of a Web application without interfering with one another and yet still be able to use each other’s work as the project progresses. To do this, you can use a single project in a Visual Studio .NET solution. You can also separate a Web application into multiple projects by dividing the development project into units to make development easier.

You can develop Web applications in single project or multi-project Visual Studio .NET solutions. The advantages and disadvantages of each method are outlined in the sections to follow.

(… Please go to MS site to read more…. )

http://support.microsoft.com/kb/307467

.NET loads PHP functions

Thursday, June 25th, 2009

Is it possible a .NET project load the functions from a PHP project ?

Here is a greate OpenSource project named Phalanger project . It allows to compile whole PHP projects into .NET assembly. And thus you can load the PHP functions in your ASP.NET project !

Phalanger
Introduction
Phalanger is a new PHP implementation introducing the PHP language into the family of compiled .NET languages. It provides PHP applications an execution environment that is fast and extremely compatible with the vast array of existing PHP code. Phalanger gives web-application developers the ability to benefit from both the ease-of-use and effectiveness of the PHP language and the power and richness of the .NET platform taking profit from the best from both sides.

The official site: http://www.php-compiler.net/

Eliminate SQL Injection Attacks Painlessly with LINQ

Monday, June 22nd, 2009

An article by Jason Schmitt. Please check it here.

Summary:

Microsoft’s LINQ to SQL technology offers .NET developers the chance to eliminate the possibility of SQL injection security vulnerabilities in their web applications.

by Jason Schmitt
May 24, 2007 

As web application security breaches and attempts rise, developers are increasingly being asked to take more responsibility for the security of their applications, and application framework vendors are building more robust security features into their platform software. Many developers have learned that the most effective way to build secure applications and prevent damaging attacks is to design and implement the applications securely from the beginning. Unfortunately, development teams often lack the training and resources to make educated design decisions about application security.

Detail content please read his article.

Update:

There is an nice related Chinese article:  “LINQ – 對付 SQL Injection 的 “免費補洞策略”" in MSN which posted by 黄忠成.