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 Hosting - Resolve Errror "Validation of viewstate MAC failed"

clock March 5, 2013 08:57 by author andy_yo

Usually we won’t got “Validation of viewstate MAC failed” error in our site all the time. Normally the site works fine and doesn't throw any errors if you load the site and use it at a regular pace.  The error only occurs when you load the page, leave it for a while, and then continue working on the page without reloading or refreshing it.  I discovered this error because I opened the site, began using it, left for lunch, came back an hour later, and when I resumed using it and did anything that caused postback, it immediately threw the above error.  Unfortunately in order to re-create the error, I have to wait a while, which is very inconvenient for testing/troubleshooting. After a few hours of reasearch I found the solutions:

About ASPHostPortal.com

ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2012, ASP.NET 4.5, ASP.NET MVC 4.0, Silverlight 5 and Visual Studio Lightswitch. Click here for more information

Error message:

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

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.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

Solution:

Yet another very teasing issue ASP .Net developers face. Solution is pretty much simple.

Add following link in your web.config file.

<pages enableEventValidation="false" viewStateEncryptionMode="Never" />

Above line should be included within section.

OR

if you don't want this solution to implemented on project level then you can add these attribute to the page(Top most line of HTML view) directive of the page which is creating issue.

That means you have to add enableEventValidation="false" viewStateEncryptionMode="Never" in page directive.

 



ASP.NET 4.5 Hosting - ASP.NET 4.5 Asynchronous pages

clock March 4, 2013 10:37 by author andy_yo

To make a page asynchronous in earlier versions of ASP.NET, the page has to implement the interface IHttpAsyncHandler and define concrete definitions to all the methods declared in the interface. This takes considerable amount of time and effort to make the page asynchronous.
In ASP.NET 4.5, we can turn the execution of any operation asynchronous by using async and await keywords. Any new page added to an ASP.NET application is considered synchronous by default. We can change this by setting value of Async property of the Page directive to true. Once this property is set, we can use async and await keywords in any method in the code behind file.

<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt; line-height: 115%; mso-ansi-language: EN-IN; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"><%@ Page Language="C#" AutoEventWireup="true" Async="true" CodeBehind="Default.aspx.cs" Inherits="Async.Default" %>
</span>

About ASPHostPortal.com

ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2012, ASP.NET 4.5, ASP.NET MVC 4.0, Silverlight 5 and Visual Studio Lightswitch. Click here for more information

This is because, performing asynchronous operations at wrong time may lead to some dangerous conditions on the server. By setting the Async attribute of the page, we are telling the server that, the current page is a safe place to perform async operations. Following is a sample page load event handler that calls a WCF service asynchronously and binds data to a GridView:

protected async void Page_Load(object sender, EventArgs e)
{
    var client = new DataServiceClient();
    var gettingCities = await client.GetCitiesAsync();
    gvCities.DataSource = gettingCities;
    gvCities.DataBind()                                               
}

Following are the set of steps performed when ASP.NET detects the await keyword in the above event handler:

  • Continues executing other synchronous tasks of the life cycle event
  • Once the above step is finished, the underlying synchronization context fires up an event saying that an async operation is pending
  • ASP.NET waits asynchronously till the pending task is completed and then it continues executing the rest of the statements
  • With above step, the life cycle (page load in this case) event is over. The control goes ahead to the next life cycle event

There is another way to achieve this. It is shown in the following snippet:

protected void Page_Load(object sender, EventArgs e)
{
    RegisterAsyncTask(new PageAsyncTask(async () =>
    {
        var client = new DataServiceClient();
        var gettingCities = await client.GetCitiesAsync();
        gvCities.DataSource = gettingCities;
        gvCities.DataBind();
    }));
}

The advantage of performing async operation this way over what we did earlier is that, it registers an asynchronous handler with the page and now the execution is not dependent on the synchronization context. Execution of the statements in the PageAsyncTask passed in is not dependent on page the page life cycle event. So, ASP.NET will not wait asynchronously after executing rest of the logic in the life cycle event. It would rather continue execution with the next life cycle event handlers. Statements in the registered task are performed whenever the dependent operation is finished.

Note that, we used the async keyword with a lambda expression. It is legal in .NET 4.5, because lambda is meant to create a single cast delegate with an anonymous method. To make the method executable asynchronously, we can use async and await with lambda.

 



ASP.NET Hosting - ASPHostPortal :: How to Modify Custom Error 404 in ASP.NET

clock February 14, 2013 11:43 by author andy_yo

One of the improvements We wanted to make after deploying our website were to add useful error pages. You know more than the YSOD (yellow screen of death). One of the major issues for me was creating a useful and informative 404 page. We wanted the page to tell the user why they got there, offer suggestions about what page they may be looking for, and allow them to search the site. So We did the development work committed the changes and had the CI machine push to the server (in the case app harbor).

1.       <system.web>

2.           <compilationdebug=truetargetFramework=4.0 />

3.           <customErrorsmode=OndefaultRedirect=~/error>

4.               <errorstatusCode=404redirect=~/404 />

5.           </customErrors>

6.       </system.web>

But We were still seeing the generic IIS sever errors! We did some searching on the internet and found a helpful property of the response object.

1.       Response.TrySkipIisCustomErrors = true;

 

About ASPHostPortal.com

ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2012, ASP.NET 4.5, ASP.NET MVC 4.0, Silverlight 5 and Visual Studio Lightswitch. Click here for more information

By default IIS will see an response with an error status code (400-500) and will automatically change the content of the response to its default error page. What this property does it tell IIS not to do that if there is already content in the body of the page. Well that was easy, right? So We made the change and pushed it to the server, and navigated to a page that didn't exist. Well the server still returned me the default 404 page, but on a 500 it would give me my custom error page. So what gives? Well here is the deal, the way routing works is that if ASP.NET cannot find a file that matches the requested URL the request is given back to IIS to handle. So in the case of a 404 ASP.NET can't find the file so its given back to IIS who uses the default static file handler to serve the request. This would be slightly different if the route had matched but then say somewhere in our code we set the status to 404. In this case it would already be in the ASP.NET pipeline and ASP.NET would server the custom 404 page.

There are two ways to solve this problem. First is the easiest which is to open up IIS Manger and go to the “Error Pages” settings under IIS and change the 404 page there to use your custom 404 page.

custom_error.png

This is fine if you can remote into the server or you're not running in the cloud where multiple instances can be started. So how then do you make that work? Well lucky that We are using IIS8 hosting, starting with IIS7 and later these settings can be added to your web.config file under the System.WebServer node.

1.       <system.webServer>

2.           <httpErrorserrorMode=Custom >

3.               <removestatusCode=404subStatusCode=-1/>

4.               <errorstatusCode=404path=/404responseMode=ExecuteURL />

5.           </httpErrors>

6.       </system.webServer>

So lets dig into what some of this code means and tell you about the tricky parts that you need to know. Before you can add a custom page you need to remove the entry for the status code as there can only be one entry per status code. The tricky bit here is knowing to set SubStatusCode to –1. This basically means all the possible sub statuses. If you like you could remove only the specific one you needed and set only the specific one. Also if you are playing around with the config you might find that there is a defaultPath attribute on the httpErrors node. This defines a “default” error page should an entry not be found in the list. The problem is that by default this is “locked” and cannot be set in an applications web.config and instead needs to be set at the machine level.  Once you add these settings to your config you should be able to see your custom error page when you navigate to a page that does not exist.



ASP.NET 4.5 Hosting - Bundling/Minification and Embedded Resources in ASP.NET

clock February 6, 2013 10:41 by author andy_yo

If you want to share your application resources(like css, javascript, images, etc) between different projects then embedded resource is a great choice. Embedded resource is also good for component/control writers because it allows component/control writers to distribute all the application resources with just a single assembly. A lot of vendors are already using this approach. It will great for component/control writers if they can leverage the ASP.NET bundling and minification for improving the performance. So, in this article we will show you how to write a very basic component(helper) which will use the ASP.NET bundling and minification feature on embedded javascript/css files.

 

About ASPHostPortal.com

ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2012, ASP.NET 4.5, ASP.NET MVC 4.0, Silverlight 5 and Visual Studio Lightswitch. Click here for more information

First of all create a new Class Library project and install the Microsoft.AspNet.Mvc, WebActivator and Microsoft ASP.NET Web Optimization Framework 1.1.0-alpha1(make sure to include the -Pre parameter in Package Manager Console) nuget packages. Next, add a reference of System.Web assembly. Then, create your control/component/helper. For demonstration purpose, We will use this sample helper:

01.          public static class HtmlHelpers
02.          {

03.                          public static MvcHtmlString NewTextBox(this HtmlHelper html, string name)

04.                          {
05.                                          var js = Scripts.Render("~/Test/Embedded/Js").ToString();
06.                                          var css = Scripts.Render("~/Test/Embedded/Css").ToString();

07.                                          var textbox = html.TextBox(name).ToString();

08.                                          return MvcHtmlString.Create(textbox + js + css);

09.                          }
10.          }

 

In this helper, I am just using a textbox with a style and script bundle. Style bundle include 2 css files and script bundle include 2 js files. So, just create 2 css files(NewTextBox1.css and NewTextBox2.css) and 2 javascript files(NewTextBox1.js and NewTextBox2.js) and then mark these files as embedded resource. Next, add a AppStart.cs file and add the following lines inside this file:

01.          [assembly: WebActivator.PostApplicationStartMethod(typeof(AppStart), "Start")]
02.          namespace Test

03.          {

04.                          public static class AppStart

05.                          {

06.                                          public static void Start()

07.                                          {

08.                                                          ConfigureRoutes();

09.                                                          ConfigureBundles();

10.                                          }

11.                                          private static void ConfigureBundles()

12.                                          {

13.                                                          BundleTable.VirtualPathProvider = new
                                                             EmbeddedVirtualPathProvider(HostingEnvironment.VirtualPathProvider);

14.                                                          BundleTable.Bundles.Add(new ScriptBundle("~/Test/Embedded/Js")

15.                                                          .Include("~/Test/Embedded/NewTextBox1.js")

16.                                                          .Include("~/Test/Embedded/NewTextBox2.js")

17.                                                          );

18.                                                          BundleTable.Bundles.Add(new StyleBundle("~/Test/Embedded/Css")

19.                                                          .Include("~/Test/Embedded/NewTextBox1.css")

20.                                                          .Include("~/Test/Embedded/NewTextBox2.css")

21.                                                          );

22.                                          }

23.                                          private static void ConfigureRoutes()

24.                                          {

25.                                                          RouteTable.Routes.Insert(0,

26.                                                          new Route("Test/Embedded/{file}.{extension}",

27.                                                          new RouteValueDictionary(new { }),

28.                                                          new RouteValueDictionary(new { extension = "css|js" }),

29.                                                          new EmbeddedResourceRouteHandler()

30.                                                          ));

31.                                          }

32.                          }

33.          }

 

The above class using WebActivator's PostApplicationStartMethod, which allows your assembly to run some code after the Application_Start method of global.asax. The Start method simply register a custom virtual path provider and two bundles which are used in our NewText helper class. But ASP.NET optimization framework will only emit a bundle url when debug="false" or when BundleTable.EnableOptimizations = true. Therefore, we also need to handle the normal javascript and css requests. For this case, the above method has also register a specific route for handling embedded resource requests using EmbeddedResourceRouteHandler route handler. Here is the definition of this handler:

01.          public class EmbeddedResourceRouteHandler : IRouteHandler
02.          {

03.                          IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext)

04.                          {

05.                                          return new EmbeddedResourceHttpHandler(requestContext.RouteData);

06.                          }

07.          }

08.          public class EmbeddedResourceHttpHandler : IHttpHandler

09.          {

10.                          private RouteData _routeData;

11.                          public EmbeddedResourceHttpHandler(RouteData routeData)

12.                          {

13.                                          _routeData = routeData;

14.                          }

15.                          public bool IsReusable

16.                          {

17.                                          get { return false; }

18.                          }

19.                          public void ProcessRequest(HttpContext context)

20.                          {

21.                                          var routeDataValues = _routeData.Values;

22.                                          var fileName = routeDataValues["file"].ToString();

23.                                          var fileExtension = routeDataValues["extension"].ToString();

24.                                          string nameSpace = typeof(EmbeddedResourceHttpHandler)

25.                                          .Assembly

26.                                          .GetName()

27.                                          .Name;// Mostly the default namespace and assembly name are same

28.                                          string manifestResourceName = string.Format("{0}.{1}.{2}", nameSpace, fileName, fileExtension);

29.                                          var stream =
                                             typeof(EmbeddedResourceHttpHandler).Assembly.GetManifestResourceStream(manifestResourceName);

30.                                          context.Response.Clear();

31.                                          context.Response.ContentType = "text/css";// default

32.                                          if (fileExtension == "js")

33.                                          context.Response.ContentType = "text/javascript";

34.                                          stream.CopyTo(context.Response.OutputStream);

35.                          }

36.          }

 

EmbeddedResourceRouteHandler returns EmbeddedResourceHttpHandler http handler which will be used to extract embedded resource file from the assembly and then write the file to the response body. Now, the only missing thing is EmbeddedVirtualPathProvider:

01.          public class EmbeddedVirtualPathProvider : VirtualPathProvider
02.          {

03.                          private VirtualPathProvider _previous;

04.                          public EmbeddedVirtualPathProvider(VirtualPathProvider previous)

05.                          {

06.                                          _previous = previous;

07.                          }

08.                          public override bool FileExists(string virtualPath)

09.                          {

10.                                          if (IsEmbeddedPath(virtualPath))

11.                                                          return true;

12.                                          else

13.                                                          return _previous.FileExists(virtualPath);

14.                          }

15.                          public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime
                             utcStart)

16.                          {

17.                                          if (IsEmbeddedPath(virtualPath))

18.                                          {

19.                                                          return null;

20.                                          }

21.                                          else

22.                                          {

23.                                                          return _previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);

24.                                          }

25.                          }

26.                          public override VirtualDirectory GetDirectory(string virtualDir)

27.                          {

28.                                          return _previous.GetDirectory(virtualDir);

29.                          }

30.                          public override bool DirectoryExists(string virtualDir)

31.                          {

32.                                          return _previous.DirectoryExists(virtualDir);

33.                          }

34.                          public override VirtualFile GetFile(string virtualPath)

35.                          {

36.                                          if (IsEmbeddedPath(virtualPath))

37.                                          {

38.                                                          string fileNameWithExtension = virtualPath.Substring(virtualPath.LastIndexOf("/") + 1);

39.                                                          string nameSpace = typeof(EmbeddedResourceHttpHandler)

40.                                                          .Assembly

41.                                                          .GetName()

42.                                                          .Name;// Mostly the default namespace and assembly name are same

43.                                                          string manifestResourceName = string.Format("{0}.{1}", nameSpace,
                                                             fileNameWithExtension);

44.                                                          var stream =
                                                             typeof(EmbeddedVirtualPathProvider).Assembly
                                                             .GetManifestResourceStream(manifestResourceName);

45.                                                          return new EmbeddedVirtualFile(virtualPath, stream);

46.                                          }

47.                                          else

48.                                                          return _previous.GetFile(virtualPath);

49.                          }

50.                          private bool IsEmbeddedPath(string path)

51.                          {

52.                                          return path.Contains("~/Test/Embedded");

53.                          }

54.          }

55.

56.          public class EmbeddedVirtualFile : VirtualFile

57.          {

58.                          private Stream _stream;

59.                          public EmbeddedVirtualFile(string virtualPath, Stream stream)

60.                          : base(virtualPath)

61.                          {

62.                                          _stream = stream;

63.                          }

64.                          public override Stream Open()

65.                          {

66.                                          return _stream;

67.                          }

68.          }

EmbeddedVirtualPathProvider class is self explanatory. It simply maps a bundling url(used above) and return the embedded request as stream. Note, this class will be invoked by ASP.NET optimization framework during bundling and minifying process. Now, just build your component/control/helper assembly. Then, create a sample ASP.NET(MVC) application and then use this component/control/helper in your page. For example, like,

[email protected]using Test.Helpers
[email protected]("New")

 



ASP.NET 4.5 Hosting - ASP.NET Web Pages - Adding Razor Code

clock January 16, 2013 06:18 by author andy_yo

In this article we will learn how to use Razor markup with C# and Visual Basic code


What is Razor?

  • Razor is a markup syntax for adding server-based code to web pages
  • Razor has the power of traditional ASP.NET markup, but is easier to learn, and easier to use
  • Razor is a server side markup syntax much like ASP and PHP
  • Razor supports C# and Visual Basic programming languages

Adding Razor Code

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<title>Web Pages Demo</title>
</head>
<body>
<h1>Hello Web Pages</h1>
</body>
</html>

Now add some Razor code to the example:

Example

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<title>Web Pages Demo</title>
</head>
<body>
<h1>Hello Web Pages</h1>
<p>The time is @DateTime.Now</p>
</body>
</html>

The page contains ordinary HTML markup, with one addition: the @ marked Razor code.

The Razor code does all the work of determining the current time on the server and display it. (You can specify formatting options, or just display the default)


Main Razor Syntax Rules for C#

  • Razor code blocks are enclosed in @{ ... }
  • Inline expressions (variables and functions) start with @
  • Code statements end with semicolon
  • Variables are declared with the var keyword
  • Strings are enclosed with quotation marks
  • C# code is case sensitive
  • C# files have the extension .cshtml

C# Example

<!-- Single statement block -->
@{ var myMessage = "Hello World"; }

<!-- Inline expression or variable -->
<p>The value of myMessage is: @myMessage</p>

<!-- Multi-statement block -->
@{
var greeting = "Welcome to our site!";
var weekDay = DateTime.Now.DayOfWeek;
var greetingMessage = greeting + " Today is: " + weekDay;
}
<p>The greeting is: @greetingMessage</p>


Main Razor Syntax Rules for VB

  • Razor code blocks are enclosed in @Code ... End Code
  • Inline expressions (variables and functions) start with @
  • Variables are declared with the Dim keyword
  • Strings are enclosed with quotation marks
  • VB code is not case sensitive
  • VB files have the extension .vbhtml

Example

<!-- Single statement block  -->
@Code dim myMessage = "Hello World" End Code

<!-- Inline expression or variable -->
<p>The value of myMessage is: @myMessage</p>

<!-- Multi-statement block -->
@Code
dim greeting = "Welcome to our site!"
dim weekDay = DateTime.Now.DayOfWeek
dim greetingMessage = greeting & " Today is: " & weekDay
End Code

<p>The greeting is: @greetingMessage</p>

About ASPHostPortal.com

ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2012, ASP.NET 4.5, ASP.NET MVC 4.0, Silverlight 5 and Visual Studio Lightswitch. Click here for more information



ASP.NET 4 Hosting - ASPHostPortal :: How to Configure Web Application to Utilise ASP.NET Application Services Database

clock November 22, 2011 04:47 by author Jervis

I come across multiple number of repeating postings at www.asp.net/forums with exceptions when post holders try to utilise ASP.NET application services database to authenticate or authorise end users. Common exceptions noted are ‘sql exceptions’ or ‘Invalid end user credentials when tried to use Login control’ or similar exception.

The reason behind most of these exceptions are not configuring web application to utilise SQL Server installed ASP.NET Application Services database. When responding to those repeating postings on asp.net forums i decided to write an article explaining this process instead of repeating the same info multiple times.

This article explains step by step process of configuring ASP.NET Web application to utilise SQL Server installed ASP.NET Application Services database.

1.       Copying and configuring connection String

2.       Copying and configuring Membership, Roles and Profile sections

3.       Using ASP.NET Web application Configuration tool to choose providers

Hope you find it helpful.

STEP 1 - Copying and Configuring Connection String

Note that configuration settings in Web.config file are inherited from machine.config file on your machine. In order to configure web application to utilise Application Services database it is required to copy related sections from machine.config file, which is located at

C:\windows\Microsoft.NET\Framework\v2.0.50727\CONFIG

NB:- Make sure that you are not making any changes to your machine.config file.

To Do:- Copy connection string from machine.config file as shown below.

<connectionStrings>
      <add name="LocalSqlServer"
      connectionString="data source=.\SQLEXPRESS;
      Integrated Security=SSPI;
      AttachDBFilename=|DataDirectory|aspnetdb.mdf;
      User Instance=true"
      providerName="System.Data.SqlClient"/>
</connectionStrings>

To Do:- Paste above connection string from machine.config into Web.config and change required properties as shown below.

<add name="<Connection String Name>"
connectionString="Server=<SQL Server NAME>;
Database=<ASP.NET Application services Database NAME>;
User ID=<user ID>;
Password=<password>"
providerName="System.Data.SqlClient"
/>

STEP 2 – Copying and Confguring Membership, Roles, and Profile Sections

Note that depending on your application requirements you need either or combination or all of these three sections.

1.       Membership

2.       Roles

3.       Profile

To Do:- Copy Membership, Roles and Profile sections from machine.config into Web.config and configure required properties.

<membership>
      <providers>

      <add name="AspNetSqlMembershipProvider"
        type="System.Web.Security.SqlMembershipProvider,
      System.Web, Version=2.0.0.0, Culture=neutral,
      PublicKeyToken=b03f5f7f11d50a3a"
      connectionStringName="LocalSqlServer"
      enablePasswordRetrieval="false"
      enablePasswordReset="true"
      requiresQuestionAndAnswer="true"
      applicationName="/"
      requiresUniqueEmail="false"
      passwordFormat="Hashed"
      maxInvalidPasswordAttempts="5"
      minRequiredPasswordLength="7"
      minRequiredNonalphanumericCharacters="1"
      passwordAttemptWindow="10"
      passwordStrengthRegularExpression=""/>   

      </providers>
</membership>

<profile>
      <providers>

      <add name="AspNetSqlProfileProvider"
      connectionStringName="LocalSqlServer"
      applicationName="/"
      type="System.Web.Profile.SqlProfileProvider,
      System.Web, Version=2.0.0.0, Culture=neutral,        
        PublicKeyToken=b03f5f7f11d50a3a"/>     

      </providers>
</profile>

<roleManager>
      <providers>

      <add name="AspNetSqlRoleProvider"
      connectionStringName="LocalSqlServer"
      applicationName="/"
      type="System.Web.Security.SqlRoleProvider,
      System.Web, Version=2.0.0.0, Culture=neutral,
      PublicKeyToken=b03f5f7f11d50a3a"/> 

      </providers>
</roleManager>

To Do:- After copying above sections into Web.config, make sure you modify minimum required attributes such as name, connectionStringName and ApplicationName

-          Note that depending on your application requirements you may modify other attributes mostly in Membership section.

After modifying minimum attributes in Membership, Roles and Profile sections, these sections looks similar as shown below.

<membership defaultProvider="AspNetMembershipProvider">
      <providers>
      <add connectionStringName="<AspNetServices
      Connectionstring Name from connectionstrings
      section"
      enablePasswordRetrieval="false"
      enablePasswordReset="true"
      requiresQuestionAndAnswer="true"
      applicationName="<WEB APP NAME>"
      requiresUniqueEmail="false"
      passwordFormat="Clear"
      maxInvalidPasswordAttempts="5"
      minRequiredPasswordLength="7"
      minRequiredNonalphanumericCharacters="0"
      passwordAttemptWindow="10"
      passwordStrengthRegularExpression=""
      name="AspNetMembershipProvider"
        type="System.Web.Security.SqlMembershipProvider,
      System.Web, Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=b03f5f7f11d50a3a"/>
      </providers>
</membership>

<roleManager enabled="true" defaultProvider="AspNetRoleProvider">
      <providers>
      <add connectionStringName="<AspNetServices
      Connectionstring Name from connectionstrings
      section"
      applicationName="<ASP.NET application NAME>"
      name="AspNetRoleProvider"
      type="System.Web.Security.SqlRoleProvider,
      System.Web, Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=b03f5f7f11d50a3a"/>
      </providers>
</roleManager>

<profile>
      <providers>

      <add name="<ProfileProvider Name>"
      connectionStringName="<From above connectionStirngs
      section that is pointing to Servies database>"
      applicationName="/<Your ASP.NET app Name>"
      type="System.Web.Profile.SqlProfileProvider,
      System.Web, Version=2.0.0.0, Culture=neutral,
        PublicKeyToken=b03f5f7f11d50a3a"/>     

      </providers>
</profile>

NB:- Make sure that application Name property is set at all the time as suggested by Scott Guthrie here.

STEP 3 – Using ASP.NET Web Application Configuration tool to choose providers

After adding and modifying required sections as explained above, save your Web.config and configure your web application to utilise ASP.NET Application Services Database as explained below.


To Do
:- Start ASP.NET Configuration tool from Website menu (shown below). Note that ASP.NET configuration tool can be initiated from Solution Explorer menu as well. 



Selecting ASP.NET Configuration opens Web Site Administration Tool in browser.

To Do:-Select Provider Configuration hyperlink as shown below.



Selecting Provider Configuration navigates to Provider page where you can choose either Single provider or different provider for each feature as shown below.

-          To Do:- You can choose either of the above options available. For this tutorial choosing ‘Select a different provider each feature’ option. By doing so each providercan choose different data sources.

Selecting Select a different provider for each feature (advanced) hyperlink navigates to next page where you can select a provider for each feature as shown below.



On this screen you can see provider name(from provider section), choose a provider for each feature i.e., Membership, Roles and Profile and select Ok.

Thats it. You are ready to fly! Configuration is done.

·    Testing:- In order to make sure your ASP.NET application services database is configured to be used by web application, you can create a new user by selecting Security tab with in Web Site Administration tool, then Create User hyperlink. After creating the user make sure that you see the same information in ASP.NET Application Services database aspnet_Users

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.



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