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 - ASPHostPortal.com :: How to Remove the XML Formatter from ASP.NET Web API Applications

clock February 27, 2015 05:36 by author Dan

 

ASP.NET Web API's default yield arrangement should be JSON, yet when I get to my Web APIs utilizing the program location bar I'm continually seeing a XML come about. At the point when chipping away at AJAX application I like to test huge numbers of my AJAX APIs with the program while taking a shot at them. While I can't investigate all demands along  these  lines, GET appeals are anything but difficult to test in the program particularly on the off chance that you have JSON seeing alternatives set up in your different programs.

On the off chance that I review a Web API ask for in many programs I get a XML reaction like this:

Why?

Web API checks the HTTP Accept headers of an appeal to figure out what kind of yield it ought to return by searching for substance wrote that it has formatters enrolled for. This programmed arrangement is one of the immense gimmicks of Web API in light of the fact that it makes it simple and straightforward to demand various types of yield from the server.

On account of programs it just so happens most send Accept headers that resemble this (Chrome for this situation):

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Web API reviews the whole rundown of headers from left to right (in addition to the quality/need banner q=) and tries to discover a media sort that matches its rundown of upheld media sorts in the rundown of formatters enlisted. For this situation it matches application/xml to the Xml formatter thus that is the thing that gets returned and showed.

To check that Web API to be sure defaults to JSON yield as a matter of course you can open the appeal in Fiddler and pop it into the Request Composer, uproot the application/xml header and see that the yield returned returns in JSON.

An accept header like this:

Accept: text/html,application/xhtml+xml,*/*;q=0.9

alternately forgetting the Accept header inside and out ought to provide for you a JSON reaction. Interestingly enough Internet Explorer 9 likewise shows JSON on the grounds that it does exclude an application/xml Accept header:

Accept: text/html, application/xhtml+xml, */*

which for once really appears to be more sensible.

Removing the XML Formatter


We can't without much of a stretch change the program Accept headers (really you can by digging into the config however its a somewhat of a bother), so would we be able to change the conduct on the server? At the point when chipping away at AJAX applications I have a tendency to not be occupied with XML results and I generally need to see JSON results at any rate amid advancement. Web API utilizes a gathering of formatters and you can experience this rundown and uproot the ones you would prefer not to utilize - as a part of this case the XmlMediaTypeFormatter.

To do this you can work with the HttpConfiguration object and the static GlobalConfiguration article used to design it:

    protected void Application_Start(object sender, EventArgs e)
    {

        // Action based routing (used for RPC calls)
        RouteTable.Routes.MapHttpRoute(
            name: "StockApi",
            routeTemplate: "stocks/{action}/{symbol}",
            defaults: new
            {
                symbol = RouteParameter.Optional,
                controller = "StockApi"
            }
        );

        // WebApi Configuration to hook up formatters and message handlers
        RegisterApis(GlobalConfiguration.Configuration);
    }

    public static void RegisterApis(HttpConfiguration config)
    {
        // remove default Xml handler
        var matches = config.Formatters
                            .Where(f => f.SupportedMediaTypes
                                         .Where(m => m.MediaType.ToString() == "application/xml" ||
                                                     m.MediaType.ToString() == "text/xml")
                                         .Count() > 0)
                            .ToList() ;
        foreach (var match in matches)
            config.Formatters.Remove(match);   
    }
}


That LINQ code is very much a bite of settled accumulations, however it does the trap to evacuate the formatter in light of the substance sort. You can likewise search for the particular formatter (XmlMediatTypeFormatter) by its write name which is less complex, however its ideal to hunt down the backed sorts as this will work regardless of the possibility that there are other custom formatters included.

Once evacuated, now the program appeal results in a JSON reaction:

It's a basic answer for a little investigating errand that is made my life simpler. Perhaps you think that it valuable as well.

Best ASP.NET Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.



ASP.NET MVC Hosting - ASPHostPortal.com :: Secure Your ASP.NET MVC Apps and Utilize Active Directory

clock February 25, 2015 06:11 by author Ben

Securing your ASP.NET MVC application ought to be priority number a single each time you begin a brand new net application. Employing the attributes Authorize and ValidateAntiForgeryToken in every single controller and action will be the only method to stay away from any safety holes. In this post I’ll show you the best way to secure your ASP.NET application by implementing the AuthorizeAttribute and ValidateAntiForgeryTokenAttribute classes.

The basics

In the extremely least, you need to add an [Authorize] attribute to every controller or controller Action in case you would like several of the controller actions to be accessible by anonymous users. As an example, you probably want ALL users to possess access for the login and register actions of one's web application.

By decorating the HomeController using the Authorize attribute (notice I didn't specify any user part) the application will avert any unauthenticated user from executing any in the actions in this controller.

[Authorize]
public class HomeController : Controller
{
  //...
}

The following is an instance of decorating a controller action with all the Authorize attribute, you desire to complete this if you only want to restrict access to a few of the actions in a controller instead of all actions.

[Authorize]
public ActionResult Create()
{
  //...
}

Safeguarding against Cross-site request forgery attack (CSRF or XSRF)

The Authorize attribute delivers protection which is sufficient in most situations. Nonetheless, there's security hole with this and therefore it opens your web application for a cross-site request forgery attack. By way of example, right after a user logs into your website the website will concern your browser an authentication token inside a cookie. Every single subsequent request, the browser sends the cookie back for the site to let the web site realize that you are authorized to take what ever action you are taking, so far every thing is very good.

Right here would be the issue with only using the Authorize attribute, let’s say that a user is logged in to your website and then they visit a spam web site by clicking on a hyperlink that points to one more web site which causes a kind post back to your site… this can be negative, your browser will send the authentication cookie to your website generating it seem as when the request came out of your website and initiated by an authenticated user when it genuinely didn’t.

The above situation is known as cross-site request forgery and can be avoided by adding the ValidateAntiForgeryToken attribute offered inside the .NET framework, this attribute is employed to detect regardless of whether a server request has been tampered with.

The initial step would be to add the ValidateAntiForgeryToken attribute to every single Post Action as follows:

[HttpPost, Authorize, ValidateAntiForgeryToken]
public ActionResult Create()
{
  //...
}

The next step is to add the HtmlHelper strategy @Html.AntiForgeryToken() inside the type within your view.

The way the ValidateAntiForgeryToken attribute operates is by checking to view that the cookie and hidden kind field left by the Html.AntiForgeryToken() HtmlHelper essentially exists and match. If they do not exist or match, it throws an HttpAntiForgeryException shown beneath:

“A essential anti-forgery token was not supplied or was invalid”

By adding the ValidateAntiForgeryToken for your controller actions your internet site will likely be prepared to stop CSRF/XSRF attacks.

Implementing Forms Authentication using Active Directory (AD)

Often times you might run across a project where you need to authenticate users of your website using Active Directory credentials, the good news is that you can use the existing “Account” controller to achieve this, only a few modifications are necessary.

When you create a new MVC Web Application project and choose the Internet Application template, the Account controller is added to the project, you can use this controller with AD to authenticate your users. For the Account controller to work with AD we need to remove all Actions but the following:

  • Logon()
  • Logon(LogOnModel model, string returnUrl)
  • LogOff()

Your Account controller should look like the following after you remove the unnecessary Actions such as ChangePassword, Register, etc.

public ActionResult LogOn()
        {
            return View();
        }
       
        [HttpPost]
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect");
                }
            }

            // if we got this far, something failed, redisplay form
            return View(model);
        }

        public ActionResult LogOff()
        {
            FormsAuthentication.SignOut();

            return RedirectToAction("Index", "Home");
        }

After this, go ahead and clean up the AccountModel as well so the only model class left is the LogOnModel:

public class LogOnModel
        {
            [Required]
            [Display(Name = "User name")]
            public string UserName { get; set; }

            [Required]
            [DataType(DataType.Password)]
            public string Password { get; set; }

            [Display(Name = "Remember me?")]
            public string RememberMe { get; set; }
        }

Lastly, add the following to the project’s web.config file:

Best ASP.NET Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.



ASPHostPortal.com Announces New Data Center in Germany

clock February 24, 2015 08:47 by author Dan

As a leading small to mid-sized business web hosting provider, ASPHostPortal.com is a company that works differently to most. Value is what we output and help the 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".

To serve our millions customers, we announce our new data center located in Frankfurt (Germany). Now, our customers can choose from our 8 different world-class data center (US (Washington & Seattle), Netherlands, Singapore, Hong Kong, United Kingdom, Australia, France (Paris), Germany (Frankfurt)).

We provide hosting service globally, All our servers are equipped with minimum Intel Dual Processor Multi Core, 8 GM RAM and the fastest 1,000 Mbps connection backbone. This is to ensure that all sites hosted on our server has an access to the best performance, reliability and connectivity feature.

With 10 years combined experience in .NET, PHP, Network Administration, System Integration and related technologies, we are an expert in the hosting market. We provide shared hosting, cloud hosting, reseller hosting, sharepoint hosting, etc with cheap price, complete features, uptime and 30 days money back guarantee. In addition, we have been awarded as one of the fastest hosting companies in the industry because of the good hosting performance that we provide. To learn more about our new data center, please visit http://asphostportal.com/Hosting-Data-Center-Germany

About ASPHostPortal.com :
ASPHostPortal.com is The Best, Cheap and Recommended ASP.NET Hosting. ASPHostPortal.com has ability to support the latest Microsoft and ASP.NET technology, such as: such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch. ASPHostPortal include shared hosting, reseller hosting, and sharepoint hosting, with speciality in ASP.NET, SQL Server, and architecting highly scalable solutions. ASPHostPortal.com strives to supply probably the most technologically advanced hosting solutions available to all consumers the world over. Protection, trustworthiness, and performance are on the core of hosting operations to make certain every website and software hosted is so secured and performs at the best possible level.



ASP.NET Hosting - ASPHostPortal.com :: How to Convert DataTable To JSON String in ASP.NET

clock February 24, 2015 06:34 by author Mark

First of all you need to create an "ASP.NET Empty Web Site". Then use the following procedure.

Step 1

Create a ConvertDataTableToJson class in the App_Code folder and provide the following:

Convert DataTable To JSON String.       
    using System.Data 
    using System.Text; 
    public class ConvertDatatableToJson 
    { 
       public string DataTableToJson(DataTable dt) 
       { 
          DataSet ds = new DataSet(); 
          ds.Merge(dt); 
          StringBuilder JsonStr = new StringBuilder(); 
          if (ds != null && ds.Tables[0].Rows.Count > 0) 
          { 
             JsonStr.Append("["); 
             for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 
             { 
                JsonStr.Append("{"); 
                for (int j = 0; j < ds.Tables[0].Columns.Count; j++) 
                { 
                   if (j < ds.Tables[0].Columns.Count - 1) 
                   { 
                      JsonStr.Append("\"" + ds.Tables[0].Columns[j].ColumnName.ToString() + "\":" + "\"" + ds.Tables[0].Rows[i][j].ToString() + "\","); 
                   } 
                   else if (j == ds.Tables[0].Columns.Count - 1) 
                   { 
                      JsonStr.Append("\"" + ds.Tables[0].Columns[j].ColumnName.ToString() + "\":" + "\"" + ds.Tables[0].Rows[i][j].ToString() + "\""); 
                   } 
                } 
                if (i == ds.Tables[0].Rows.Count - 1) 
                { 
                   JsonStr.Append("}"); 
                } 
                else    
                { 
                   JsonStr.Append("},"); 
                } 
             } 
             JsonStr.Append("]"); 
             return JsonStr.ToString(); 
          } 
          else 
          { 
             return null; 
          } 
       }

Step 2

Insert the grid view control into the Default.aspx page then write the following design code:

<asp:GridView ID="ui_grdVw_EmployeeDetail" runat="server" Width="50%" AutoGenerateColumns="false" HeaderStyle-CssClass="pageheading"> 
    <Columns> 
    <asp:TemplateField HeaderText="S.NO"> 
    <ItemTemplate> 
    <%#Container.DataItemIndex+1 %> 
    </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Employee ID"> 
    <ItemTemplate> 
    <asp:Label ID="ui_lbl_EmployeeID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Emp_id") %>'></asp:Label> 
    </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Employee Name"> 
    <ItemTemplate> 
    <asp:Label ID="ui_lbl_EmployeeName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Emp_Name") %>'></asp:Label> 
    </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Employee Post"> 
    <ItemTemplate> 
    <asp:Label ID="ui_lbl_EmpJob" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Emp_job") %>'></asp:Label> 
    </ItemTemplate> 
    </asp:TemplateField> 
    <asp:TemplateField HeaderText="Department"> 
    <ItemTemplate> 
    <asp:Label ID="ui_lbl_Department" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Emp_Dep") %>'></asp:Label> 
    </ItemTemplate> 
    </asp:TemplateField> 
    </Columns> 
    </asp:GridView> 
    <br /> 
    <asp:Button ID="ui_btn_Convert1" runat="server" Text="Manually Convert To Json" OnClick="ui_btn_Convert1_Click" /><br /><br /><br /> 
    <asp:Label ID="ui_lbl_JsonString1" runat="server"></asp:Label>

Step 3

Now, open the Deafult.asps.cs then write the following code:
    using System; 
    using System.Data;
 

    public partial class _Default : System.Web.UI.Page 
    { 
       #region Global Variable 
       DataTable dt; 
       ConvertDatatableToJson dtJ; 
       string JsonString = string.Empty;    
       #endregion 
        
       protected void Page_Load(object sender, EventArgs e) 
       { 
          if (!IsPostBack) 
          { 
             ui_grdvw_EmployeeDetail_Bind(); 
          } 
       }       
       protected void ui_grdvw_EmployeeDetail_Bind() 
       { 
          dt = new DataTable(); 
          EmployeeRecord employeeRecord = new EmployeeRecord(); 
          dt = employeeRecord.EmpRecord(); 
          ViewState["dt"] = dt; 
          ui_grdVw_EmployeeDetail.DataSource = dt; 
          ui_grdVw_EmployeeDetail.DataBind(); 
       }       
       protected void ui_btn_Convert1_Click(object sender, EventArgs e) 
       { 
          dtJ = new ConvertDatatableToJson(); 
          JsonString = dtJ.DataTableToJson((DataTable)ViewState["dt"]); 
          ui_lbl_JsonString1.Text = JsonString; 
       } 
    }

Step 4

Press F5, run the project.

Now, convert the DataTable to a JSON string using the newtonsoft DLL.

Step 1

Download the Newtonsoft DLL and move it to the ASP.Net project's bin folder.

Step 2

Then, insert a button and label UI Control in the Deafult.aspx page as in the following:

<asp:Button ID="iu_btn_Convert2" runat="server" Text="Newtonsoft Convert To Json" OnClick="iu_btn_Convert2_Click" /> 
    <br /> 
    <br /> 
    <asp:Label ID="ui_lbl_JsonString2" runat="server"></asp:Label>

Step 3

Now, write the following code in Default.aspx.cs:
using this namespace

using Newtonsoft.Json;

And then:

protected void iu_btn_Convert2_Click(object sender, EventArgs e) 
    { 
       dt = (DataTable)ViewState["dt"]; 
       JsonString = JsonConvert.SerializeObject((DataTable)ViewState["dt"]); 
       ui_lbl_JsonString2.Text = JsonString; 
    }

Now, run the project and click on the Newtonsoft Convert to JSON     

Best ASP.NET Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.   



ASPHostPortal.com Announces Fast Joomla 3.4 Hosting Solution

clock February 18, 2015 08:39 by author Dan

Supported by powerful servers, ASPHostPortal.com is one of the leading Windows hosting providers offering quality service with premium support. Our servers are built using the latest technology. We are passionate about hosting and strive to deliver an excellent level of service to each customer. Our web hosting plans are suitable for small to medium-sized blogs, personal, charity or business websites. Today, we launch Joomla 3.4 hosting with superior technology and affordable price.

Joomla is an award-winning content management system (CMS), which enables you to build Web sites and powerful online applications. Many aspects, including its ease-of-use and extensibility, have made Joomla the most popular Web site software available. Best of all, Joomla is an open source solution that is freely available to everyone. Now, Joomla has released the new version Joomla 3.4

What’s new in Joomla! CMS 3.4

Front-end Module Editing
Incorporating Front End Module editing allows you to edit modules directly on the page without the need to use the admin dashboard.

Decoupling com_weblinks
Joomla accomplished the first step in this is by removing com_weblinks from the core distribution. These extensions are maintained on GitHub.

Composer Integration

Joomla is integrating Composer into the CMS for managing external dependencies such as the Joomla! Framework and PHPMailer.

No CAPTCHA reCAPTCHA
Google introduced a no CAPTCHA CAPTCHA API in December 2014. We updated the reCAPTCHA plugin to protect your login and registration forms against spam.

Core en-GB standardization
It will provide translation teams with an easy framework and guidelines to create their own style guides to ensure consistency throughout the project.

With more than 1 million followers, ASPHostPortal is an expert in the hosting market. We provide Joomla 3.4 Hosting only for $5/month with 30 days money back guarantee. In addition, we have been awarded as one of the fastest hosting companies in the industry because of the good hosting performance this web host provides. To provide fast hosting speed, our company utilizes 6 state-of-the-art data centers located in the USA, Netherlands, Singapore, France, United Kingdom and Australia. To learn more about Joomla 3.4 Hosting, please visit http://asphostportal.com/Joomla-3-4-Hosting

About ASPHostPortal.com:
ASPHostPortal.com is The Best, Cheap and Recommended ASP.NET Hosting. ASPHostPortal.com has ability to support the latest Microsoft and ASP.NET technology, such as: such as: WebMatrix, Web Deploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch. ASPHostPortal include shared hosting, reseller hosting, and Sharepoint hosting, with speciality in ASP.NET, SQL Server, and architecting highly scalable solutions. ASPHostPortal.com strives to supply probably the most technologically advanced hosting solutions available to all consumers the world over. Protection, trustworthiness, and performance are at the core of hosting operations to make certain every website and software hosted is so secured and performs at the best possible level.



ASP.NET Hosting - ASPHostPortal.com :: How to Debug Your ASP.NET Projects Running Beneath IIS

clock February 18, 2015 06:06 by author Ben

If you've carried out any coding in ASP.NET then you understand how critical debugging is. By default Visual Studio comes with its personal stripped down web service that it runs every single time you debug your application as a way to serve up pages. 90% of the time that little net server just isn't powerful or quick enough to maintain up with an enterprise level application. A lot of organizations will have you map your web site to [Internet Information Services][IIS] that is a suitable internet server that comes with Windows. IIS features a lot a lot more possibilities and is much more robust for application hosting (understandably considering that which is its whole goal) whereas the little web service that starts inside the default configuration of visual studio hardly compares.


The downside of possessing your application run by IIS is that it's not immediately apparent how you can debug the application. Pressing F5 nevertheless tries to launch the dinky internet service that comes with Visual Studio. Lots of people speedily determine that they could attach to the procedure thread began by IIS for the application it's operating. It really is generally named one thing like "w3wp.exe". You do this by going to the "debug" menu in Visual Studio and then choosing "Attach to Process". This brings up a bit window having a list of running processes. Obtaining the IIS method for the application and clicking attach will then start Visual Studio's debugger. You are able to then hit the pages hosted by IIS and hit your breakpoints within your code.

Even though this really is fine and functions, it is a giant discomfort to visit Debug > Attach to Process every single single time you must debug your application. You can generate a macro that would do the work for you personally, but why create a macro when Visual Studio will actually do it for you. Let me show you how to setup your project to work with IIS by default when debugging. You will not ever need to navigate your procedure tree once more.

You'll find two forms of internet projects in .NET, Internet sites and Web Applications. There is considerably debate about which 1 is far better for development, but this post is not about that so I will not get into it right here. Nonetheless, these two project varieties have distinct properties menus and configuring them to use IIS when debugging is slightly different in each and every of them. For simplicity's sake I decided to break it up into two sections, one for net apps, and one for websites. Please see the section that corresponds for your project variety. (If you're making use of ASP.NET MVC then you are utilizing a internet application)

Web sites

If your project is actually a website and not a net app, then listed below are the measures to configure it to use IIS when debugging. This assumes you already have IIS setup and hosting your project.

  1. First open up your project and open the solution explorer.
  2. Right-click on your project node and navigate to "Property Pages".
  3. Navigate to "Start Options" item in the left pane.
  4. In the "Server" section make sure "Use custom server" is checked.
  5. In the "Base URL:" field put in the address you have mapped to your project. (Usually the address you put in your hosts file)
  6. You're basically done, but another option I like to set on this page is "Don't open a page. Wait for request from an external application." I set this because I don't like closing a million browser tabs for every time I debug. I usually just leave my browser open behind visual studio and when I debug I prefer to just switch to the browser and refresh rather than have Visual Studio open a new tab.

Web Applications

If your project is a web application and not a website, then here are the steps to configure it to use IIS when debugging.

  1. First open up your project and open the solution explorer.
  2. Right-click on your project node and navigate to "Properties".
  3. Find the "Web" tab on the left-hand side.
  4. Under the "Servers" section select "Use Local IIS Web Server".
  5. This next step varies by how you have your project set up.
    • If you have your project mapped to IIS already then simply put the local URL in the "Project Url" field.
    • If you have NOT mapped your project to IIS yet then it is usually more convenient to click the "Create Virtual Directory" button and let it do it for you. (If you have not set up IIS on your machine correctly then this will fail) Note: Keep in mind that this is not the same as creating a new website in IIS. It creates a virtual directory under the default website that comes with IIS. This can cause problems if you were bad and you used application relative paths instead of absolute paths as root relative paths refer to the website root, not the virtual directory root. Learn how to make your web project build absolute paths based on an application relative root path using the tilde (~).

You're basically done, but another option I like to set on this page is "Don't open a page. Wait for request from an external application." I set this because I don't like closing a million browser tabs for every time I debug. I usually just leave my browser open behind visual studio and when I debug I prefer to just switch to the browser and refresh rather than have Visual Studio open a new tab.

Best ASP.NET Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.





ASP.NET Hosting - ASPHostPortal.com :: How to Add and Edit Data In ASP.NET Web Pages

clock February 16, 2015 06:13 by author Dan

Really, I'll take a gander at including information first. To add another book to the database, we have to give a title, ISBN number, depiction and we have to include a writer and classification. The book will gain a BookId esteem consequently as a consequence of making the BookId field in the database an Identity segment. The initial 3 qualities require textboxes inside a structure:

<form action="" method="post">
<div class="row">
    <span class="label"><label for="title">Title:</label></span>
    <input type="text" name="title" id="title" size="50" />
</div>
<div class="row">
    <span class="label"><label for="isbn">ISBN:</label></span>
    <input type="text" name="isbn" id="isbn" size="20" />
</div>
<div class="row">
    <span class="label"><label for="description">Description:</label></span>
    <textarea cols="50" rows="8" name="description" id="description"></textarea>
</div>


Things are progressing pretty well. The creator and classification are not all that direct. A determination of writers and classifications as of now exist in the database in their own different tables. The main piece of tthe writer or classification record that is put away in the book record is the Primary Key quality for the writer or class, as a Foreign Key worth. This relates the suitable writer or classification record the book record. In this way, when adding a writer to a book, for instance, everything we need is the ID of the writer. Notwithstanding, introducing a rundown of ID qualities to the client is very little utilize. How are they going to know which Id fits in with which creator? The answer is to utilize a html <select> component, likewise referred to in ASP.NET circles as a dropdown list. A select component contains one or more <option> components.


Every choice has a quality ascribe (which is utilized to hold the ID), and it incorporates some content which characterizes the choices accessible to the client in an all the more cordial way. On account of creators, a mix of first name and last name will likely be the most supportive approach to do this. Thus, in the code zone at the highest point of the page, we have to characterize a Database item, and after that question it for the information for the select rundown:

var db = Database.Open("Books");
var authors = db.Query("SELECT AuthorId, FirstName + ' ' + LastName AS AuthorName FROM Authors");


While the SQL looks somewhat occupied, it just returns two qualities - the AuthorId for each one creator, and the first name and last name linked with a space between, and conveyed under the pseudonym "AuthorName". The thing to do next is to apply these to the select rundown

<div class="row">
    <span class="label"><label for="authorId">Author:</label></span>
    <select name="authorId" id="authorId">
        <option value="">-- Select Author --</option>
    @{
        foreach(var author in authors){
             <option value="@author.AuthorId">@author.AuthorName</option>

        }
    }
    </select>
</div>


The primary alternative is the default one, and is given no quality whatsoever. After that, every alternative tag is given the ID having a place with the matching creator in the rundown. At the point when the structure is submitted, just the ID quality is posted back (which is all we are after). The same procedure is emulated for applying a select rundown of classifications:

<div class="row">
    <span class="label"><label for="categoryId">Category:</label></span>
    <select name="categoryId" id="categoryId">
        <option value="">-- Select Category --</option>
    @{
        foreach(var category in categories){


             <option value="@category.CategoryId">@category.Category</option>   
        }
    }
    </select>
</div>


Finally the form is finished off:

<div class="row">
    <span class="label">&nbsp;</span>
    <input type="submit" name="action" id="action" value="Add" />
</div>
</form>


At the point when the structure is posted back, the qualities entered by the client are assembled and embedded into the database:

if (IsPost){
  var sql = "INSERT INTO Books (Title, ISBN, Description, AuthorId, CategoryId) VALUES (@0, @1, @2, @3, @4)";
  db.Execute(sql, Request["title"], Request["isbn"], Request["description"], Request["authorId"], Request["categoryId"]);
}


Notice the qualities @0, @1 and so forth in the SQL? They are parameter placeholders, and protet against SQL infusion, which is an endeavor to pass vindictive code to the database. At the point when the Database.Execute() strategy is called, the SQL is passed in initially, emulated by the wellspring of the parameter values. For this situation, the greater part of the qualities originate from the Request.Form gathering (despite the fact that the shorthand form Request[index] is utilized. Things are referenced by their list, which is the name of the structure field. The qualities are passed into the strategy in the same request that their parameters show up in the SQL.

Altering a current book requires a just about indistinguishable structure. Be that as it may, the structure needs to know which book is being altered. This point of interest is passed in the URL to the EditBook.cshtml page. Connections are made in the posting page (Default.cshtml):

foreach(var push in db.Query(sql, Request["CategoryID"])){

foreach(var row in db.Query(sql, Request["CategoryID"])){
    <h2>@row.Title</h2>
    <p><strong>Author:</strong> @row.FirstName @row.LastName<br />
    <strong>ISBN:</strong> @row.ISBN <br/>
    <strong>Description:</strong> @row.Description <br />
    <strong>Category: </strong> @row.Category</p>
    <a href="@Href("~/EditBook", row.BookId)">Edit</a>
}


The last line of code demonstrates the Href() assistant being utilized to connection to EditBook.cshtml utilizing steering, so the record postfix is not required, and the Id of the book is attached like this: EditBook/5, or EditBook/7 and so on. This worth is drawn from the URL utilizing the UrlData() assistant and utilized as a parameter for the SQL that gets the pointed out book's points of interest, alongside the information for the writers and classifications drop down records:

var db = Database.Open("Books");
var Id = UrlData[0].AsInt();
var sql = "SELECT Title, ISBN, Description, AuthorId, CategoryId FROM Books WHERE BookId = @0";
var book = db.QuerySingle(sql, Id);
var categories = db.Query("SELECT CategoryId, Category FROM Categories");
var authors = db.Query("SELECT AuthorId, FirstName + ' ' + LastName AS AuthorName FROM Authors");


The structure itself presents the book to be altered:

<form action="" method="post">
<div class="row">
    <span class="label"><label for="title">Title:</label></span>
    <input type="text" name="title" id="title" value="@book.Title" size="50" />
</div>
<div class="row">
    <span class="label"><label for="isbn">ISBN:</label></span>
    <input type="text" name="isbn" id="isbn" value="@book.ISBN" size="20" />
</div>
<div class="row">
    <span class="label"><label for="description">Description:</label></span>
    <textarea cols="50" rows="8" name="description" id="description">@book.Description</textarea>
</div>
<div class="row">
    <span class="label"><label for="authorId">Author:</label></span>
    <select name="authorId" id="authorId">
    @{
        foreach(var author in authors){
            if(author.AuthorId == book.AuthorId){
                <option value="@author.AuthorId" selected="selected">@author.AuthorName</option>
            } else {
                <option value="@author.AuthorId">@author.AuthorName</option>
            }
        }
    }
    </select>
</div>
<div class="row">
    <span class="label"><label for="categoryId">Category:</label></span>
    <select name="categoryId" id="categoryId">
    @{
        foreach(var category in categories){
            if(category.CategoryId == book.CategoryId){
                <option value="@category.CategoryId" selected="selected">@category.Category</option>
            } else {
                <option value="@category.CategoryId">@category.Category</option>
            }       
        }
    }
    </select>
</div>
<div class="row">
    <span class="label">&nbsp;</span>
    <input type="submit" name="action" id="action" value="Edit" />
</div>



</form>


Inside the code for both the writer and classification dropdowns, the Id of the book to be altered is contrasted and every Id of the writer or class, and if there is a match, selected="selected" is added as a credit to the alternative. When WebMatrix is discharged completely, there may be aides for drop down records, yet this is more or less great Beta 1. Presently we have a structure that gets the chose book and presentations it for altering, yet nothing happens if the client clicks submit. The code square needs to be changed at the highest point of the record to overhaul the chose book with the new values, and after that redisplay it, so it now resembles this:

var db = Database.Open("Books");
var Id = UrlData[0].AsInt();
var sql = "";
if (IsPost)
{
  sql = "UPDATE Books SET Title = @0, ISBN = @1, Description = @2, AuthorId = @3, CategoryId = @4 WHERE BookId = @5";
  db.Execute(sql, Request["title"], Request["isbn"], Request["description"], Request["authorId"], Request["categoryId"], Id);
}
sql = "SELECT Title, ISBN, Description, AuthorId, CategoryId FROM Books WHERE BookId = @0";
var book = db.QuerySingle(sql, Id);
var categories = db.Query("SELECT CategoryId, Category FROM Categories");
var authors = db.Query("SELECT AuthorId, FirstName + ' ' + LastName AS AuthorName FROM Authors");


Another code test has been connected if the page IsPost(), and in that, the qualities are gotten from the Request accumulation and passed into the SQL to upgrade the database. At that point the code proceeds as in the recent past, recovering the chose book for redisplay with the redesigns.

Best ASP.NET Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.



ASP.NET Hosting - ASPHostPortal.com :: Key Points of ASP.NET VNext

clock February 12, 2015 05:58 by author Mark

Microsoft openness and open source approach leads to ASP.NET vNext – The next generation of .NET. In this article we will discuss some of key points of vNext.
In vNext we have cloud optimization mode. Traditional scenario, we are having entire .NET Framework and CLR install to design and deploy ASP.NET application.
According to me Microsoft had spilt the framework and CLR in vNext as .NET Core and everything else. In the .NET Core we have cloud optimized runtime core with very minimum foot prints. Everything else can be very easily downloaded using Nuget repository. This is actually made compiler as service (CaaS) scenario.

(kpm restore – To compile and download required libraries from nuget.)
We would be having only minimum footprint and essential libraries to run the ASP.NET application. A minimum footprint delivers faster results. During compile time only essentials components are deployed application wise, each application can have different version of .NET vNext side by side.

(kvm list - to see what versions of the ASP.NET vNext are available.)
Dependency injection is design pattern used to manage orchestration between loosely coupled objects. Build in DI in ASP.NET vNext manages configuring services and libraries. Environment specific service / libraries can configure through DI. This is very useful methodology while working with cross platform development and deployment.
ASP.NET MVC and Web API have been unified into a single programming model. The new framework removes a lot of overlap between the existing MVC and Web API frameworks. It uses a common set of abstractions for routing, action selection, filters and model binding.
The Roslyn provides open-source C# and Visual Basic compilers with rich code analysis APIs. It enables building code analysis tools with the same APIs that are used by Visual Studio. (more details on Roslyn compiler in next article)
The .NET Foundation is an independent organization to foster open development and collaboration around the growing collection of open source technologies for .NET. We can find more details at this link.

Summary

  • Cloud and server-optimization.
  • NuGet everything - even the runtime itself.
  • Side by side - deploy the runtime and framework with your application.
  • ASP.NET MVC and Web API have been unified into a single programming model.
  • Dependency injection out of the box.
  • New flexible and cross-platform runtime.
  • All Open Source via the .NET Foundation and takes contributions.
  • Roslyn compiler.

TOP No#1 Recommended ASP.NET Hosting

ASPHostPortal.com

ASPHostPortal.com  is the leading provider of Windows hosting and affordable ASP.NET Hosting. ASPHostPortal proudly working to help grow the backbone of the Internet, the millions of individuals, families, micro-businesses, small business, and fledgling online businesses. ASPHostPortal has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch, ASPHostPortal guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability.



ASPHostPortal.com Announces Powerful Sitefinity 7.3 Hosting Solution

clock February 10, 2015 18:56 by author Dan

As a technology focused web host, ASPHostPortal are designed to support popular web development technologies. Windows and ASP.NET hosting are at the core of its business practice. They have over 10 years combined experience in .NET, PHP, Network Administration, System Integration and related technologies to support mission critical hosting for applications built on these platforms. Today, they launch Sitefinity 7.3 hosting with powerful network and affordable price.

Sitefinity by Telerik is an ASP.NET web content management platform engineered to make managing your website a more positive, empowering and usable experience. Sitefinity is the first and only CMS to enable enterprises to take full advantage of all three mobile development strategies— Responsive Web Design, mobile websites, and mobile apps, easily and effectively—and all from one CMS user interface.

Sitefinity 7.3 introduces lead scoring, integration with SharePoint Online, extended ASP .NET MVC support and more.

Directly Impact Revenue With Lead Scoring
Manage your lead scoring criteria according to various data points collected across channels.

Complement SharePoint Online
Provide a natural extension to all your SharePoint workflows and wrap a compelling presentation around your core business documents.

Build fast, and light with new ASP .NET MVC Features
MVC based widgets for each of your dynamic modules with automatically generated Razor templates.

With 7 data centers that located in USA Europe, Australia and Asia, ASPHostPortal is superior provider in the hosting market. They provides Sitefinity 7.3 Hosting only from $5/month with 30 days money back guarantee. In addition, ASPHostPortal has been awarded as one of the best hosting companies in the industry because of the good hosting performance this web host provides. To provide best hosting performance, this company always maintains the server with expert team in ASP.NET Technology. To learn more about Sitefinity 7.3 Hosting, please visit http://asphostportal.com/Sitefinity-7-3-Hosting

About ASPHostPortal.com :
ASPHostPortal.com is The Best, Cheap and Recommended ASP.NET Hosting. ASPHostPortal.com has ability to support the latest Microsoft and ASP.NET technology, such as: such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch. ASPHostPortal include shared hosting, reseller hosting, and sharepoint hosting, with speciality in ASP.NET, SQL Server, and architecting highly scalable solutions. ASPHostPortal.com strives to supply probably the most technologically advanced hosting solutions available to all consumers the world over. Protection, trustworthiness, and performance are on the core of hosting operations to make certain every website and software hosted is so secured and performs at the best possible level.



ASP.NET 5 Hosting - ASPHostPortal.com :: Debugging jQuery in ASP.NET

clock February 10, 2015 07:17 by author Mark

When an ASP.NET developer uses jQuery or JavaScript (clientside programming) in his code, the question always arises of how to debug this code. We can debug in code behind with breakpoints. But what for clientside scripting. Some people say use "alert()", but I don't think this is a sufficient way to do it.
So the good news is that we have the "debugger" keyword to debug your line of code.
Use debugger before your code, where you want to start debugging.
See the following code:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-1.7.1.min.js"></script>
        <script>
            $(document).ready(function () {
                $(':radio').click(function () {
                    debugger;
    //Get the value of Radio button
                    var _GetVal = $(this).attr('value');
                });
             });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
           First
            <input type="radio" name="rd1" value="10" />
            <input type="radio" name="rd1" value="11" />
            Second
            <input type="radio" name="rd1" value="12" />
            <input type="radio" name="rd1" value="13" />
        </div>
        </form>
    </body>
    </html>

This is a simple ASP.NET in page code. When the user clicks a radio button, debugging will automatically start, due to the debugger command. In the above program, when the user clicks on the radio button we stored its value in the _Getval variable.

$(document).ready(function () {
                $(':radio').click(function () {
                    debugger;
    //Get the value of Radio button
                    var _GetVal = $(this).attr('value');
                });
             });

You can see that when I declare a _GetVal variable, before I use "debugger" because from here I want to start debugging. See the following images.
Figure 1: When user clicks in the radio

Figure 2: When the user presses F10 (the same way as what we did in code behind using a breakpoint).

In the image above you can see that the _GetVal value is 10 now. So with the use of the debugger you can start your debugging in ASP.NET.
And please remember, when you finish debugging or publish your page, please remove debugger from your code.
If you have any query, Please send your valuable Comments. Happy Programming

TOP No#1 Recommended ASP.NET Hosting

ASPHostPortal.com

ASPHostPortal.com  is the leading provider of Windows hosting and affordable ASP.NET Hosting. ASPHostPortal proudly working to help grow the backbone of the Internet, the millions of individuals, families, micro-businesses, small business, and fledgling online businesses. ASPHostPortal has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch, ASPHostPortal guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability.



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