November 27, 2013 05:33 by Mike
Environment variables are a great thing for when you publish your website to multiple places. It doesn't matter if you publish it to testing / staging / production environment or if you're publishing your site to several servers which require different methods to be called / different values assigned to parameters.
Let's create a web application project:
1. Open Visual Studio 2010
2. Create New Project -> ASP.NET Web Application
As you can see, you automatically have two configuration options:
3. Right click on the project in the Solution Explorer. Click on Properties and click on Build tab.
4. Under that tab you have many configuration options. The field we're interested in is "Conditional compilation symbols". While on Debug mode, we will write a variable name in this field. Example: "vDebug"
5. After saving, you will have an identifier for when in Debug mode.
6. Before testing our work, we're gonna create another Configuration. Click on the configuration drop down list and choose Configuration Manager.
7. Add new Configuration - TestRelease:
8. Now place the variables in Release Configuration and in TestRelease Configuration. I've placed the variables: vRelease and vTestRelease
9. Now for the test. Create a similar code on your Default.aspx.cs page:
When you will run the code, you'll see that for each configuration option it will it the correct method.
November 22, 2013 10:10 by Mike
Partial view is like a regular view with a file extension .cshtml. We can use partial views in a situation where we need a header, footer reused for an MVC web application. We can say that it’s like a user control concept in ASP.NET. Here I am going to explain how to create a partial view in an MVC 4 ASP.NET application.
First add a view to the shared folder with the view name _Product. The best way to create a partial view is with the name preceded by '_', because the name specifying that it is reusable.
Here in this example, I am using the partial view to display the item selected in the webgrid.
Layout = null;
<meta name="viewport" content="width=device-width" />
We can call the partial view in a normal view like:
Html.Partial returns a string, Html.RenderPartial calls Write internally, and returns void. You can store the output of Html.Partial in a variable, or return it from a function. You cannot do this with Html.RenderPartial because the result will be written to the Response stream during execution. So @html.RenderPartial() has faster execution than @html.Partial() due to RenderPartial giving quick response to the output.
We can call the partial view if the grid has a selected item. The code block is shown here:
November 13, 2013 07:13 by Ben
One of new features from ASP.NET 4.5 is Regex. Lets start by the new Regex Api introduced with the framework. The improvement that has been made is minor yet handy at certain cases. The Regex class of .NET 4.5 supports Timeout. Lets take a look how to work with it.
Lets try to write a simplest RegEx validator to look into it.
Here in the code you can see I simply check a string with a Regular expression. It eventually finds success as Pattern matches the string. Now this code is little different than what we have been doing for last few years. The constructor overload of Regex now supports a Timespan seed, which indicates the timeout value after which the Regular expression validator would automatically generate a RegexMatchTimeoutException. The Match defined within the Regex class can generate timeout after a certain time exceeds.
You can specify Regex.InfiniteMatchTimeout to specify that the timeout does not occur. The value of InfiniteMatchTimeout is -1ms internally and you can also use Timespan.Frommilliseconds(-1) as value for timespan which will indicate that the Regular expression will never timeout which being the default behavior of our normal Regex class. Regex also supports AppDomain to get default value of the Timeout. You can set timeout value for "REGEX_DEFAULT_MATCH_TIMEOUT" in AppDomain to set it all the way through the Regular expressions being used in the same AppDomain. Lets take a look how it works.
Now this works exactly the same as the previous one. Here the Regex(new feature of ASP.NET 4.5) constructor automatically checks the AppDomain value and applies it as default. If it is not present, it will take -1 as default which is Infinite TImeout and also if explicitely timeout is specified after the default value from AppDomain, the Regex class is smart enough to use the explicitly set value only to itself for which it is specified. The Regex Constructor generates a TypeInitializationException if appdomain value of Timespan is invalid. Lets check the internal structure.
This is the actual code that runs in background and generates the timeouts. Infact while scanning the string with the pattern, there is a call to CheckTimeout which checks whether the time specified is elapsed for the object. The CheckTimeout throws the exception from itself.
The Constructor sets DefaultMatchTimeout when the object is created taking it from AppDomain data elements.
If the pattern is supplied from external or you are not sure about the pattern that needs to be applied to the string, it is always recommended to use Timeouts. Basically you should also specify a rational limit of AppDomain regex default to ensure no regular expression can ever hang your application.
This is a small tip on the new Regex enhancements introduced with .NET 4.5 recently. I hope you like it. More to come shortly.
November 1, 2013 10:44 by Mike
Professional web hosting provider – ASPHostPortal.com proudly announced the integration of the latest Web Deploy 3.5 in all web hosting plans. We are the first few hosting company that provide ASP.NET hosting plan that support the brand new Web Deploy 3.5 Hosting.
WebDeploy v3.5 is now available and there are a few features to consider in this minor release:
- Load Balancer Support with Session Affinity.
- Encrypting web.config Settings Post-Publish.
- App Offline Template.
- Seamless integration with IIS Manager (IIS7 and above), Visual Studio (2010 and above) for creating packages and deploying them onto a machine, both locally and remotely.
- Integration with WebMatrix for deploying and downloading web applications.
- Seamless integration with the Web Platform Installer to install community web applications simply and easily.
- Web application packaging and deployment.
- Web server migration and synchronization.
- Automatic backup of Web Sites before making any changes.
- In addition to the IIS Manager, Visual Studio 10, Web Matrix tasks can be performed using the command-line, PowerShell Cmdlets or public APIs.
According to ASPHostPortal.com, it's Web Deploy 3.5 offerings are distinguished by their low cost, with many of the hosting services supporting the technology being of the more expensive variety.
For more information about this topics or have any enquiries related to Web Deploy 3.5 hosting, please visit http://www.asphostportal.com
ASPHostPortal.com is a hosting company that best support in Windows and ASP.NET-based hosting. Services include shared hosting, reseller hosting, and sharepoint hosting, with specialty in ASP.NET, SQL Server, and architecting highly scalable solutions. As a leading small to mid-sized business web hosting provider, ASPHostPortal strive to offer the most technologically advanced hosting solutions available to all customers across the world. Security, reliability, and performance are at the core of hosting operations to ensure each site and/or application hosted is highly secured and performs at optimum level.