ASP.NET 4.5 and ASP.NET Core 1 Hosting BLOG

Tutorial and Articles about ASP.NET 4.0 and the latest ASP.NET 4.5 Hosting

ASP.NET 4 Hosting - ASPHostPortal :: How to use RangeValidator control in ASP.NET 4.0

clock February 29, 2012 07:15 by author Administrator

If you want to understand how RangeValidator works, by example, you can develop a simple test web page. This page uses a single Button web control, two TextBox controls and a RangeValidator control that validates the first text box. If validation fails, the RangeValidator control displays an error message, so you should place this control immediately next to the TextBox it’s validating. The second text box does not use any validation.

The next picture shows the appearance of the page after a failed validation attempt.




The markup for this page defines a RangeValidator control, sets the error message, identifies the control that will be validated, and requires an integer from 32 to 78. These properties are set in the .aspx file, but they could also be configured in the event handler for the Page.Load event. The Button automatically has its CauseValidation property set to true, because this is the default.


A number (32 to 78):


<asp:TextBox id=”validatedBox” runat=”server” />
    <asp:RangeValidator id=”RangeValidator” runat=”server”
    ErrorMessage=”This Number Is Not In The Range”
    ControlToValidate=”validatedBox“
    MaximumValue=”78” MinimumValue=”32“
    ForeColor=”Red” Font-Bold=”true”
    Type=”Integer” />

<br /><br />


Not validated:


<asp:TextBox id=”notValidatedBox” runat=”server” /><br /><br />
<asp:Button id=”cmdOK” runat=”server” Text=”OK” OnClick=”cmdOK_Click” />
<br /><br />
<asp:Label id=”lblMessage” runat=”server” EnableViewState=”False” />


An additional Label control is used to report when the page has been posted back and the event handling code has executed. Its EnableViewState property is disabled to ensure that it will be cleared every time the page is posted back.


The next code lines manage responds to the button click:


protected void cmdOK_Click(Object sender, EventArgs e)
{
lblMessage.Text = “cmdOK_Click event handler executed.”;
}


When you open the page for the first time in modern browsers, the error message is is hidden. But if you type an invalid number (validation will succeed for an empty value) and press the Tab key to move to the second text box, an error message will appear automatically next to the offending control. This is because ASP.NET adds a special JavaScript function that detects when the focus changes. The actual implementation of this JavaScript code is somewhat complicated, but ASP.NET handles all the details for you automatically. As a result, if you try to click the OK button with an invalid value in validatedBox, your actions will be ignored, and the page won’t be posted back.


In case if you want to see what will happen on a browser which does not support client-side validation (i.e. down-level browser), you should set the RangeValidator.EnableClientScript property to false, and rerun the page. Now error messages won’t appear dynamically as you change focus. However, when you click the OK button, the page will be returned from the server with the appropriate error message displayed next to the invalid control.


If you want to ensure that your web page behaves the same in modern and older browsers, you must specifically abort the event code if validation hasn’t been performed successfully. The next code lines correct this problem:


protected void cmdOK_Click(Object sender, EventArgs e)
{
// Abort the event if the control isn’t valid.
if (!RangeValidator.IsValid) return;
lblMessage.Text = “cmdOK_Click event handler executed.”;
}


When the page page contains multiple validation controls, you should follow different approach. In ASP.NET world every web form provides its own IsValid property. This property will be false if any validation control has failed. It will be true if all the validation controls completed successfully. If validation was not performed (for example, if the validation controls are disabled or if the button has CausesValidation set to false), you’ll get an HttpException when you attempt to read the IsValid property. In this case the next code is better:


protected void cmdOK_Click(Object sender, EventArgs e)
{
// Abort the event if any control on the page is invalid.
if (!Page.IsValid) return;
lblMessage.Text = “cmdOK_Click event handler executed.”;
}


Reasons why you must trust ASPHostPortal.com


Every provider will tell you how they treat their support, uptime, expertise, guarantees, etc., are. Take a close look. What they’re really offering you is nothing close to what
ASPHostPortal does. You will be treated with respect and provided the courtesy and service you would expect from a world-class web hosting business.

You’ll have highly trained, skilled professional technical support people ready, willing, and wanting to help you 24 hours a day. Your web hosting account servers are monitored from three monitoring points, with two alert points, every minute, 24 hours a day, 7 days a week, 365 days a year. The followings are the list of other added- benefits you can find when hosting with us:


-
DELL Hardware
Dell hardware is engineered to keep critical enterprise applications running around the clock with clustered solutions fully tested and certified by Dell and other leading operating system and application providers.
- Recovery Systems
Recovery becomes easy and seamless with our fully managed backup services. We monitor your server to ensure your data is properly backed up and recoverable so when the time comes, you can easily repair or recover your data.

- Control Panel
We provide one of the most comprehensive customer control panels available. Providing maximum control and ease of use, our Control Panel serves as the central management point for your ASPHostPortal account. You’ll use a flexible, powerful hosting control panel that will give you direct control over your web hosting account. Our control panel and systems configuration is fully automated and this means your settings are configured automatically and instantly.

- Excellent Expertise in Technology
The reason we can provide you with a great amount of power, flexibility, and simplicity at such a discounted price is due to incredible efficiencies within our business. We have not just been providing hosting for many clients for years, we have also been researching, developing, and innovating every aspect of our operations, systems, procedures, strategy, management, and teams. Our operations are based on a continual improvement program where we review thousands of systems, operational and management metrics in real-time, to fine-tune every aspect of our operation and activities. We continually train and retrain all people in our teams. We provide all people in our teams with the time, space, and inspiration to research, understand, and explore the Internet in search of greater knowledge. We do this while providing you with the best hosting services for the lowest possible price.

- Data Center

ASPHostPortal modular Tier-3 data center was specifically designed to be a world-class web hosting facility totally dedicated to uncompromised performance and security
- Monitoring Services
From the moment your server is connected to our network it is monitored for connectivity, disk, memory and CPU utilization – as well as hardware failures. Our engineers are alerted to potential issues before they become critical.

- Network
ASPHostPortal has architected its network like no other hosting company. Every facet of our network infrastructure scales to gigabit speeds with no single point of failure.

- Security
Network security and the security of your server are ASPHostPortal’s top priorities. Our security team is constantly monitoring the entire network for unusual or suspicious behavior so that when it is detected we can address the issue before our network or your server is affected.

- Support Services
Engineers staff our data center 24 hours a day, 7 days a week, 365 days a year to manage the network infrastructure and oversee top-of-the-line servers that host our clients’ critical sites and services.



ASP.NET Hosting - ASPHostPortal :: Using IIS7 URL Rewrite Module with ASP.Net Routing

clock February 21, 2012 08:18 by author Jervis

Short, simple URLs improve a site’s search engine optimization, usability, and security.  URL rewriting and routing can be used to accomplish this.  URL rewriting/routing improves SEO by distilling URLs down to a set of keywords that search engines can easily parse.  It improves usability by abstracting the file structure of the site, which may change, and presenting a simplified site structure.  It improves security by hiding the details of how a site is implemented by removing querystring and file suffixes.

Before the release of IIS7 and .Net 3.5, most ASP.Net developers implemented URL rewriting by one of the following methods:

1.       Implementing ISAPI filters for IIS

2.       Developing their own HttpModule

3.       Licensing a configurable third party ISAPI filters like ISAPI Rewrite, or HttpModule like UrlRewriter.Net.

With the introduction of IIS7, Microsoft released an add-on module that implements URL rewriting.  The URL Rewrite module works similarly to ISAPI filter based URL rewriting, but has the advantage of being more closely integrated to the web server.  The configuration is XML driven by settings added to the web.config.  The module can map URLs based on regex pattern matching, or by a list of 1-to-1 URL mappings.  In addition, configuration can be done through the IIS7 GUI.

The diagram below shows how URL rewriting using the URL Rewrite Module for IIS7 works.



Pros:

·         Easy to implement

·         Mapping changes do not require a recompile and code deployment

·         Management through IIS7 UI

Cons:

·         Can’t be integrated with a CMS or database driven URL maps

·         No built-in functionality for reverse lookups

·         Locks you in to using IIS7

.Net 3.5 introduced ASP.Net routing, a new way of mapping URLs to HttpHandlers.  ASP.Net routing works differently from any form of URL rewriting.  URL rewriters change an incoming request’s URL and then hands off the request.  ASP.Net doesn’t change the request URL.  Instead, it loads HttpHandlers directly based on its mapping logic.

The following diagram shows how ASP.Net rewriting fits into the request processing pipeline.



Pros:

·         Easier to integrate with CMS or database driven URL mappings

·         Reverse mapping is easier if you build for it

·         Custom implementation offers greater flexibility – like giving developers a neat way of doing A/B testing

Cons:

·         Easy to turn into spaghetti code

·         Changes to mapping logic often require a recompile and code redeploy

·         Takes more effort to implement

For more explanation about the differences between these two methods, read this article.

These two methods can be combined to get some of the advantages of each.  The following example involves an ASP.Net site that contains pages managed by a content management system.  We’d like to have some of the ease of implementation, and maintenance from the IIS module, but we also need to allow some URL mappings to be controlled by the CMS.

The following shows the web.config settings for the IIS Rewrite Module.  The first rule applies the 1-to-1 mappings in the Custom Mappings rewriteMap section.  The second rule routes page requests to four main categories within the site to paths that the ASP.Net URL rewriter module will handle later on in the request lifecycle.

<rewrite>
       <clear />
       <rule name="Apply Custom Rewrite Map" enabled="true" stopProcessing="true">
              <match url="(.*)" />
              <conditions logicalGrouping="MatchAll">
                     <add input="{Custom Mappings:{PATH_INFO}}" pattern="(.+)" />
              </conditions>
              <action type="Rewrite" url="{C:0}" appendQueryString="true" />
       </rule>
       <rule name="Product Type Pages" stopProcessing="true">
              <match url="^(Music|Movies|Games|Accessories)(/)?$" />
              <conditions logicalGrouping="MatchAll" />
              <action type="Rewrite" url="Pages/{R:1}" />
       </rule>
       <rule name="All Other Pages" enabled="true" stopProcessing="true">
              <match url="^([_0-9a-z-]+)(/)?$" />
              <conditions logicalGrouping="MatchAll" />
              <action type="Rewrite" url="Pages/{R:1}.aspx" />
       </rule>
       <rewriteMaps>
              <rewriteMap name="Custom Mappings">
              <add key="/Home" value="Pages/Default.aspx" />
              <add key="/Search" value="Pages/Search/Default.aspx" />
              <add key="/Admin" value="Pages/Admin/SiteAdmin.aspx" />
       </rewriteMap>
       </rewriteMaps>
</rewrite>

The following shows the web.config setting for ASP.Net routing.

<addassembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>


… 

<httpModules>
       <addname="UrlRoutingModule"type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>

In ASP.Net routing, we don't explicitly implement the HttpModule. Instead we create a class that implements the IRouteHandler interface and load this class in the Application_Start() event handler of the global.asax.

Here is our implementation of the IRouteHandler interface:

public class RouteHandler<T> : IRouteHandler where T : IHttpHandler, new()
       {
              public string VirtualPath { get; set; } 

              public RouteHandler(string virtualPath)
              {
                     this.VirtualPath = virtualPath;
              } 

              public IHttpHandler GetHttpHandler( RequestContext requestContext )
              {
                     IHttpHandler ret = null;
                     foreach ( var value in requestContext.RouteData.Values )
                     {
                           requestContext.HttpContext.Items[ value.Key ] = value.Value;
                     } 

                     ret = ( VirtualPath != null )
                           ? (IHttpHandler)BuildManager.CreateInstanceFromVirtualPath(
                           VirtualPath, typeof( T ) )
                           : new T(); 

                     return ret;
              }
       }

Most of this code is boiler plate to load an HttpHandler based on the mappings that you load up in the Application_Start() handler.

Our example site uses URL mappings defined in an XML file exported by a CMS. So we call a method in the Application_Start() handler in the global.asax that loads this XML file and creates a route for each entry. We do a bit of hand waving here by excluding the code for the CMS.Common.GetRoutes() method because it's probably unnecessary to go over the details parsing an XML.

void Application_Start(object sender, EventArgs e)
{
       RegisterRoutes(RouteTable.Routes);


public static void RegisterRoutes(RouteCollection routes)
{
       CMS.Route[]cmsRoutes = CMS.Common.GetRoutes(); 

       foreach (CMS.Route iCmsRoute in Booking cmsRoutes)
       {
              routes.Add(iCmsRoute.Name, new Route
              (
                      iCmsRoute.RequestPath,
                      new CustomRouteHandler(iCmsRoute.HandlerPath)
              ));
       }
}

Custom mapping URLs to HttpHandlers allows us to create websites with improved SEO, usability and security. The IIS7 URL Rewrite module and ASP.Net routing are two useful tools to map URLs. Each has its advantages and disadvantages, but can be used together to meet various URL mapping requirements.



ASP.NET 4 Hosting - ASPHostPortal :: How to Fix Login failed for user 'IIS APPPOOL\ASP.NET v4.0' error in IIS7

clock February 16, 2012 06:08 by author Jervis

After running a ASP.NET website on IIS 7.5 for the first time on a Windows 7 computer, sometimes you will face this problem:

Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.

To fix this issue, try changing the (Process Model) Identity of your website's Application Pool to use the NetworkService account (or the less secure LocalSystem account).  By default, IIS7 seems to set the Application Pools Identity to 'ApplicationPoolIdentity', instead of NetworkService or LocalSystem. 

Here's a step-by-step guide for determining your websites Application Pool, then changing its Process Model Idenitty in IIS7: 

1.       Open Internet Information Services (IIS) Manager.

2.       In the Connections sidebar, drill down into Default Web Site and click on your website.

3.       Now in the Actions sidebar (on right side), click on Advance Settings... In the popup box, under General you will see your Application Pool listed for your website (in my case the app pool is: ASP.NET V4.0).

4.       Click Cancel...  If you choose, you can change the Application Pool here, but for the sake of this example we just wanted to find out what the website's App Pool was.

Now that we know the Application Pool that is configured for your website, we now want to change the app pool's (Process Model) Identity to 'NetworkService', here's how:

1.       Open Internet Information Services (IIS) Manager.

2.       In the Connections sidebar, click on Application Pools.

3.       Now right-click on theApplication Pool that your website is using (in this case my site is using the ASP.NET v4.0 application pool), and select Advanced Settings... from the menu.

4.       In the Advanced Settings pop-up box, locate the Process Model -> Identity section and click on the Application Pool Identity. 

5.       In the Application Pool Identity pop-up box, change the Built-in account to NetworkService (or if you want LocalSystem), then click OK, and click OK again to save your Advanced Settings changes.

After changing the Application Pool's Identity to NetworkService (or LocalSystem) you should now be able to get your ASP.NET site to run successfully on an IIS7 web server. Good luck!!



Cheap ASP.NET 4.5 Hosting

We’re a company that works differently to most. Value is what we output and help our customers achieve, not how much money we put in the bank. It’s not because we are altruistic. It’s based on an even simpler principle. "Do good things, and good things will come to you".

Success for us is something that is continually experienced, not something that is reached. For us it is all about the experience – more than the journey. Life is a continual experience. We see the Internet as being an incredible amplifier to the experience of life for all of us. It can help humanity come together to explode in knowledge exploration and discussion. It is continual enlightenment of new ideas, experiences, and passions


Author Link


 

Corporate Address (Location)

ASPHostPortal
170 W 56th Street, Suite 121
New York, NY 10019
United States

Tag cloud

Sign in