ASP.NET TipsUpdate: After the exposure to WPF MVVM this year (2012), I started learning about ASP.NET MVC. I used both C++/CLI and C# in my previous work for Iris Identification web site,since one of our customers uses C# but our libraries are C++. Updated 3/18/2013 Index
How can I eliminate the error "$ is not defined in jscript" in MVC4?Under MVC4, _Layout.cshml has Scripts.Render("~/bundles/jquery") and thus there should not beany need for jquery file to be defined in each page. However, when I added jscript file in the standard way, I get the error "$ is not defined" which indicates jquery is not loaded. It turned out that under MVC4 you add a section at the end and add jscript there. That is, in your .cshtml file, you do the following: ... (main page here) @section scripts { <script src="@Url.Content("~/Scripts/myscript.js")" type="text/javascript"> </script> } How can I use SqlServer Compact 4.0 in MVC4?After installing VS2010 SP1 Tools for Sql Server Compact 4.0, I still could not use the Data for Sql Server Compact 4.0 I added in my project. In earlier version, WebActivator was doing it. It is no longer installed. It turned out that after EntityFramework 4.3, you use Web.config to set the default connection in the following way for SqlServer Compact 4.0: <entityFramework> <!-- <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" > <parameter> <parameter value="v11.0, IntegratedSecurity=True, MultipleActiveResultSets=True" /> </parameter> </defaultConnectionFactory> --> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework"> <parameters> <parameter value="System.Data.SqlServerCe.4.0"/> </parameters> </defaultConnectionFactory> </entityFramework> Why SQL Server Compact 4.0 not showing up in template in VS2010?SQL Server Compact 4.0 was build for VS2008. In order to make it available under VS2010, youhave to install Visual Studio 2010 SP1 Tools for SQL Server Compact 4.0 ENU Setup. How can I use native DLLs in ASP.NET?You can use native C/C++ DLLs in .NET by P/Invoke or C++/CLI. When you want to use your own C++ DLLs, you don't want to putthem in Windows/System32 directory (or Windows directory). Even though IIS creates bin directory for .NET web services or web application, it won't search for native DLLs in this directory. It turned out that ASP.NET has class Global derived from System.Web.Application. which allows you to modify the environment variable PATH so that you can force ASP.NET to load libraries from bin directory. Note that "bin" is relative to the virtual directory of the application. Thus, you always specify "bin" even though the actual path ishttp://localhost/MyTest/bin. In C# web services, ================== class Global is not available as default. You do Add New Item → Select Global Application Class. Click Add. You will get Global.asax which produces Global.asax.cs code. You modify this file as public class Global : System.Web.HttpApplication { // add Server path bin to environment variable PATH protected void Application_Start(object sender, EventArgs e) { // here are the lines added String tempPath = Environment.GetEnvironmentVariable("PATH"); String binPath = Server.MapPath("bin"); String fullPath = String.Concat(tempPath, ";",binPath); Environment.SetEnvironmentVariable("PATH",fullPath); } ... } In C++/CLI web services, ======================== you automatically get Global.asax.h. You modify this file as follows: // remove Win32 version of the same function name #undef GetEnvironmentVariable ... protected: void Application_Start(Object ^sender, EventArgs ^e) { System::String^ tempPath = Environment::GetEnvironmentVariable("PATH"); String^ binPath = Server->MapPath("bin"); String^ fullPath = String::Concat(tempPath, ";",binPath); System::Environment::SetEnvironmentVariable("PATH",fullPath); } ... In ASP.NET web application, ========================== you add it at Page_Load(): protected void Page_Load(object sender, EventArgs e) { // add bin to PATH so that delay load can load dll String tempPath = Environment.GetEnvironmentVariable("PATH"); String binPath = Server.MapPath("bin"); String fullPath = String.Concat(tempPath, ";", binPath); Environment.SetEnvironmentVariable("PATH", fullPath); } Note that the serach path change due to this only applies to thedll loaded after the application starts. Therefore when you createsC++/CLI library which calls C++ libraries, you have to set the C++/CLI projectconfiguration to set delay load C++ libraries. Property Pages → Configuration Properties → Linker → Input → Delay Loaded DLLs How can I fix the VSdebugger failing on webservice?When I created the webservice project from Visual Studio 2005 and triedto debug, I get error,saying Unable to start debugging on the web server. The server does not support debugging of ASP.NET or ATL Server applications. Click Help for more information on how to enable debugging. You may also want to refer to the ASP.NET and ATL Server debugging topic in the online documentation.When I use the Internet Explorer to get more infoby typing "http://localhost/xmlweb/xmlweb.asmx". I got Server Error in '/(name)web' Application ----------------------------------------- The current identity (GIFU\ASPNET) does not have write access to 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files'Note that GIFU is the PC machine name. You should substitue your own. The way to fix this problen is the following: $ cd c:\Windows\Microsoft.NET\Framework\v2.0.50727 $ aspnet_regiis -ga "GIFU\ASPNET"Start granting GIFU\ASPNET access to the IIS metabase and other directories used by ASP.NET. Finished granting GIFU\ASPNET access to the IIS metabase and other directories used by ASP.NETwhere -ga (grant access). After this, Visual Studio 8 can run the webservice inside the debugger. Another error I had is Unable to start debugging on the web server. Debugging failed because integrated Window authentication is not enabled. Please see Help for assistance.In order to fix this problem, you should go to Control Panel → Administratice Tools → Internet Information Services Click on Web Sites → properties → Directory Security Tab→ Anonymous access and authentication control Click Edit.Authentication Methods dialog shows up. Check at the bottom of the page sayingIntegrated Windows authentication. How can I reinstall ASP.NET?If you know what to do, it is easy (otherwise how can I think of this?). $ cd %WinDir%\Microsoft.NET\Framework\v2.0.50727 $ aspnet_regiis -iStart installing ASP.NET (2.0.50727) ........................ Finished installing ASP.NET (2.0.50727). How can I make C# web service usable in IIS?There is a difference in how we services are installed between C# and C++/CLI. C++/CLI web services are installed into Inetpub/wwwroot directory and IIS configuration is automatically set. Unfortunately this won't happenfor C# web services. You get an error when trying to run .asmx file: 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: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.Source Error: Line 19: ASP.NET to identify an incoming user. Line 20: --> Line 21: <authentication mode="Windows" /> Line 22: <!-- Line 23: The <customErrors> section enables configuration Source File: c:\inetpub\wwwroot\xmlwebcs\web.config Line: 21After you publish your web services from IDE(build → publish), you do the following: Control Panel → Administrative Tools → Internet Infomation Services (After publishing in c:\Inetput\wwwroot\xmlwebCS as an example) xmlwebCS Properties (which has a directory icon) Application Settings Create (it picks the right name) Execute Permissions -> Scripts and ExecutablesApplication Protection -> Low (IIS Process)xmlwebCS icon changes to the application icon. After this, you can use the internet explorer to run using URLhttp://localhost/xmlwebCS/Service1.asmx. How can I resolve the staxmem.dll error for IIS installation?p>Trying to install IIS on my ThinkPad, I get staxmem.dll not found error even though I see the file is there. I even inserted a XP Installation disk and the installer does not recognize the file. Unless this http://support.microsoft.com/kb/894351, I would never find a way. In my case, the local group policy file was corrupt (how would I know this?). Here is how.esentutl /g c:\Windows\security\database\secedit.sdbwhich told me that the file is corrupt. When it is corrupt, here is how to fix. esentutl /p c:\Windows\security\database\secedit.sdbI was able to install IIS after this repair. Microsoft site above has the methodof recreating the local group policy file by hand. Where is IIS 7 Manager?Somehow enabling IIS on Windows7 does not install IIS7 Manager.I had to download from here. After the installation, you start by inetmgr.exe. How can I resolve the IIS 7.0 error "HTTP Error 404.13: exceeds the request content length"?Under IIS 7.0 (in Windows 7), I get the following error: HTTP Error 404.13 - Not FoundThe request filtering module is configured to deny a request that exceeds the request content length.The easiest way is to install IIS 7 Manager above. Then start it byinetmgr.exe. In the middle pane, you find an icon "RequestFiltering" ![]() Double Click on it to get ![]() On the right pane, you find "Edit Feature Setting". Click to getEditRequesFiltering Setting dialog. Modify the value for Maximum alloowed content length (Bytes). ![]() Another way is to use command line,explained http://forums.iis.net/t/1066272.aspx and here. %windir%\system32\inetsrv\appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:1000000 Then you get Applied configuration changes to section "system.webServer/security/requestFiltering" for "MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST" or if you only want to set it for your app: %windir%\system32\inetsrv\appcmd set config "Default Web Site/" -section:requestFiltering -requestLimits.maxAllowedContentLength:1000000 |
Programming‎ > ‎