CISP238

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What are some of the things that you need to take into account when you start considering adding bundling to your web application?

"Bundling enables you to combine multiple files of the same type, such as CSS or JavaScript, into a single file for download. Bundling becomes important when you want to get multiple scripts to the client side but the browser only supports a certain number of connections to a single domain. As the page is rendered, each call to a server may end up being queued. Therefore, bundling is a great benefit once you have more than five or six items being down- loaded. These items can include images, CSS files, JavaScript files, and any other item that could be downloaded from the server. The size of the items that you are bundling is important as well. Putting multiple large files into a single bundle may slow the load time down because your users are getting a very large file over a single channel as opposed to two smaller files that can be downloaded at the same time. Lastly, the amount of change that happens in your scripting is important. Each change to the underlying scripts causes a new bundle to be downloaded to the client. Thus, if you are doing a lot of work on one script, you may want to move it out of the bundle and keep it separate; otherwise, the browser sees the bundle containing multiple files as new, although only one file has actually changed."

What is the difference between using @Html.TextboxFor and @Html.Textbox?

"The TextboxFor helper specifically binds a property on the model to an HTML element. This binding is achieved through a lambda expression that helps the system identify which property on the model should be used for the binding. The Textbox element typically takes a string name rather than a direct model binding. The name given to the helper is the name given to the HTML element that it creates. However, as long as the name that is passed into the helper is the same as the property name with which you want it to be related, the model binder can interpret which property should get the returned value."

How does the Razor view engine understand the difference between code that is supposed to run and text that should not be changed or affected, simply passed through?

"The primary way that the Razor view engine knows the difference between code that it should process and text that needs to simply be passed through straight into the HTML is through the use of the @ character and curly brackets, {}. If C# (or VB) code is after the @ character or contained within a set of curly brackets, then the view engine knows to run the code. The view engine is also smart enough to realize when you start an HTML element, so it switches back into text-reading mode. However, if you want it to return to code processing mode, you need to preface it with the @ character again; thus, you may have @ code within other @-labeled constructs."

What are the differences between .intro p, p.intro, and p, .intro?

. intro p will match those items of type p that are completely contained within any kind of element that has a class named intro . The style p.intro will select all elements with class intro that are fully contained within a type element of p. The style p, .intro will select those elements that are either of type p or have their class set to "intro.""

What does attribute routing enable you to do that the template approach does not?

Attribute routing enables developers to define the URL that an action will respond to directly on the action, as opposed to a standard template. One of the primary problems with the template approach is that there always seemed to be at least one route in an application that could not be easily managed through the template approach. The developer would have to either hard-code a route in the RouteConfig file or otherwise manipulate how the action is named and called to ensure that it could be managed in the "one size fits all" approach of template-based routing. With attribute routing, however, you can determine at the action level what URL that action would respond to."

What is the difference between authentication and authorization?

Authentication is when a user confirms who they are, generally through the combination of username and password. Authorization comes after the user has been authenticated and is the determination about whether the user can take a particular action or set of actions.

Why is it not as straightforward to use base classes on views as it is to use base classes on either a Web Form web page or an MVC controller?

Controllers and web pages are traditional OO classes, so even though they are already inheriting other classes, it is easy to add an intermediate class as long as that intermediate class extends the class that the page was already inheriting. However, views are a different kind of approach; they do not have a class definition or anything that enables you to create an inheritance scheme. They are instead a value that is processed.

What are some of the various tools in Visual Studio that help developers manage styles for web pages?

Design mode: Enables the developer to see the rendered version of the HTML source code Visual aids: Provides different views of the rendered output in Design mode, including tags, borders around elements, etc. Formatting toolbar: Visible when in Design mode, the formatting toolbar enables developers to assign and/or create styles directly from within the window.

Why were friendly URLs implemented and what advantages do they bring to ASP.NET Web Forms development?

Friendly URLs were implemented for several reasons. The first is that it makes addresses easier to remember, as the user doesn't have to include the extension on the URL. This makes URLs used for advertising much more effective. Another reason is that it makes other URLs more predictable and guessable. This gives users confidence that they can find information on your site. The last big reason is search engine optimization, which is better supported because friendly URLS allows the elimination of query strings in favor of URL variables, turning http://www.servername.com/product.aspx?id=8 to http://www.servername.com/ product/8 or even http://www.servername.com/product/Product_Name."

What other options do you have for passing the list of hobbies to the view if you did not use the ViewBag or any of the ViewBag-type approaches (i.e., ViewData , etc.)?

If you are not going to pass information to a view through the use of a ViewBag, then best approach is to create a ViewModel, which in this case is a class with two properties: the list of hobbies and the UserDemographics item that is currently being used as the model."

With the setup you currently have after the Try it Out activities, what do you think the default behavior of the screen would be after caching was added to the ItemList page? What would happen when you add an item?

If you create a new item, there is a chance that the item will not be displayed in the list page, especially if you had recently visited the list page. This is because the cache was set to 20 minutes, so visiting the list page, creating or editing an item, and then immediately going back to the list page will likely result in the list itself being cached; therefore, the new list will not be called until after expiration of the previous cache. This is a perfect example of when caching can cause stale data to be presented to the user.

Convention plays an important role in ASP.NET MVC. Must the view name always match the action name?

No, views do not always have to match the name of the action. If you return a View() , then it is expecting a one-to-one correlation; however, you also have the capability to add the name of the view to be returned. This enables you to return any view from a controller action as long as you appropriately define the view method that is returned.

What would be the expected behavior of the server when a user puts HTML code only into the Title field of a view that is linked with the following code? What happens if HTML code is put only in the Description field? [ValidateInput(true)] public class TestController : Controller { [HttpPost] public ActionResult Create(MyModel model) { return View(); } public ActionResult Create() { return View(); } } public class MyModel { [Required] [StringLength(50)] public string Title { get; set; } [Required] [AllowHtml] [StringLength(5000)] public string Description { get; set; } }"

Request validation has been turned on based on the attribute on the controller, so the only way any HTML would be allowed through the process is if it were turned on at the model level. If you examine the model, however, you will see that the Description property has the appropriate attribute to allow HTML. Thus, any HTML in the Title would cause an exception to be thrown, while any HTML in the Description would be allowed through the request process.

How do you add special jQuery code when using Ajax.Helpers in an ASP.NET MVC view?

The Ajax.Helper class has four different events that you can add to a JavaScript function: OnBegin enables you to know when a call is getting ready to happen, but before the call to the server; OnComplete is called after the call to the server has completed but before the page is updated; OnFailure handles any error conditions; and OnSuccess is called after the page is updated. Each of these enables you to add a JavaScript function to the workflow.

From what you know about code first migration (in the Entity Framework), what kind of information do you think is contained within the __MigrationHistory table?

The _MigrationHistory table keeps a record of every time the update database command was run in that database. It stores the name of the migration that was created by the developer, the context to which the migration was assigned, and information on the model(s) that were used. If you looked in the table, you would be easily able to determine the first two items, but the model information is stored in a binary format and is not intended to allow reverse migration outside the context of the Entity Framework.

What is the advantage of using the Layout command in the ViewStart page?

The advantage of using the Layout command in the ViewStart file is that you do not need a hard link between your views and your layout. If you did not have the ViewStart and you wanted to change the layout to point to another file, you would have to go into every page to make the change. The ViewStart enables you to specify your primary layout page and then assign it by default.

How does the model binder know how to bind the properties of nested types, or objects that are properties on other objects?

The model binder is able to determine nested object properties by using dot notation. For example, suppose you have an object structure like the following: public class Parent { public Child Child { get; set; } } public class Child { public GrandChild GrandChild { get; set; } } public class GrandChild { public string SomeProperty { get; set; } } A textbox would be able to set the property on the grandchild by ensuring that the name of the textbox element is " Child.GrandChild.SomeProperty " where the model that was passed to the view is a parent."

Imagine you are working with an ASP.NET Web Forms page and you place a RangeValidator above a RequiredValidator when they are both validating the same control. What would be the difference in behavior if you switched the order of the validation controls?

The order in which validation controls are added to the page does not affect anything about the actual validation.

Your e-commerce site sells women's clothing. What kind of information would you gather if you wanted to get an understanding of the color palette that the user preferred?

There are a couple of different ways that you can gather this kind of information. One would be to simply ask users what colors they prefer. While not very sophisticated, it tends to get relatively accurate information. The other, and more subtle, approach is to track the various colors that users view during their shopping visits, perhaps also tracking search terms in case they also regularly contain colors.

What could you do with the information that you just gathered?

There are a lot of different things that you can do with this kind of information. For example, you can shade the background of the pages that you display to that user with a color. Another simple personalization would be displaying the user's preferred color(s) automatically so the user doesn't have to make the selection.

What would be some reasons to use a more direct route to the database, such as ExecuteQuery rather than using the traditional EF approach?

There are multiple reasons why you might want to use a more direct approach to the data- base, including response time and performance, complicated queries, integration with other applications that are using database access, and the need to keep consistent behavior between the applications.

What are some of the challenges with adding a timer to a web page for which the results from the call update a section of the page?

There are several potential problems with using a timer to refresh content. The first of these is the bandwidth and processing that may be used unnecessarily. The browser will continue to make those calls as long as the page is open. The user could have gone to the page, looked around for a few minutes, and then decided to do something else without closing the browser. The page will continue making calls even though the user is not present. Another problem that may be experienced could result from transient network outages or server problems; rather than getting the expected content part of the page, the user will instead be trying to deal with an error.

If you were a new developer on a project for which a bug report is received regarding a page found at http://www.servername.com/results/ , where would you look for the code that caused that specific defect?

There are two main approaches to finding the code that responds to a request to http://www.servername.com/results . The first is to look through the project to see if there is a folder with the name of "results." If there is, then there is a good chance that the default file in the directory responds to that request. This means that it is being served by an ASP.NET Web Forms page. If this does not provide a result, the next step would be to look into the Controllers directory to determine whether there is a controller that would be used to handle requests to this URL, most likely "ResultsController." If this controller does exist, look in the actions to find the one that would serve a get request to the base URL. If you are unable to find anything there, you need to check the RouteConfig.cs file to evaluate whether it contains a hard-coded route that will handle this approach. If so, then follow this routing suggestion to find the appropriate handler.

Whenever the application starts, what two files are responsible for setting configuration items such as minimum length for a password?

These two files are the Startup.Auth.cs and IdentityConfig.cs . The Startup.Auth.cs file creates the UserManager and SignInManager as well as configures the way that cookies are going to be used for authentication. IdentityConfig.cs sets up the password validation requirements as well as other default user login details such as lockout periods and maximum attempts.

Your user is on a page at http://www.servername.com/admin/list.aspx and you have the following link: <href="~/default.aspx">Home</a> . Where would they end up if they clicked the link?

They would end up at http://www.servername.com/Admin/~/default, where they would most likely get a 404 error for Page Not Found. If the anchor tag were given the extra attribute for runat="server" , then the system would know to replace the ~ with the application root directory. However, without the runat="server" , the HTML from an HTML element turns into an HTML control, so the system does not do any additional interpretation of the code.

Create the jQuery and HTML changes necessary to change the color of only this particular <h1> element when your mouse moves over the content of this specific <p> element: <h1>Title</h1> <p>Content</p>"

This change is only supposed to work on these particular elements, so the first thing you should do is add an id to each so that your jQuery work can select the correct item. After adding id s, you can set the hover function of the <p> element to change the css color value of the <h1> element. All code is shown here: <h1 id="colorchange">Title</h1> <p id="hoverover">Content</p> $(document).ready(function () { $("#hoverover").hover( function () { $("#colorchange").css('color', 'yellow'); }, function () { $("#colorchange").css('color', 'green'); }); });

How do you provide your HTML elements on a page with access to styles from an external style sheet?

To allow the content of a web page to access styles contained in an external stylesheet you need to create a link between the web page and the external stylesheet. That link is created through the use of a link element that is placed in the header of the web page. A link looks like <link href="styles.css" rel="Stylesheet" type="text/css" />"

Margins and padding have different effects on an element. If you were going to stretch the box of an element, which would you use?

To stretch the "box" of an element you would use the padding property. The padding property extends the visible box of the element, while the margin property pushes the visible box away from the adjacent element. If, for example, you set the background-color of an element containing some text, padding would extend the background-color past the text, extending the colored area. Using margin will move the colored box without changing its size.

What steps would you need to take if you wanted to implement the Unobtrusive AJAX jQuery library in an ASP.NET Web Form page?

Using the Unobtrusive AJAX jQuery library in a Web Form application can be done in several ways. Perhaps the easiest is to include the script references to the JavaScript libraries, just as you did in the example. You can then manually add the attributes to the element that will be firing the change, typically an anchor link. An example would be the following: &lt;a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#thelementToReplace" href="/URL TO CALL"&gt;Displayed Text&lt;/a&gt; The expectation is that you have a URL that will return some HTML that is appropriate to display in the element identified in the attributes."

Why do the code examples that are interacting with the database have the following line? What benefit does it offer? using (RentMyWroxContext context = new RentMyWroxContext())

Using the using statement ensures that the item being created, in this case the DbContext, is disposed of upon completion. Taking this step ensures that the .NET Garbage Collector will be able to pick this item out of memory the next time the collector runs. Otherwise, this item would likely linger in memory for a longer period and have a more long-term effect on memory usage, perhaps affecting the user experience.

When you are working with ASP.NET Web User Controls, what would happen if you have a property that is a string and you pass an integer into it through an attribute? What happens if the property is an integer and you pass a string into it?

When you are working with attributes in the markup, it is important to remember that every- thing is actually a string, so putting an integer into a property defined as a string will not cause any problems; the property will be populated with the string version of the integer. It is going the other way that's a problem. When you are putting a string value into a non-string attribute, you must ensure that the string value can be parsed into the appropriate type. If you don't do this correctly, such as by putting the value "two" into an integer field, you will get several warnings. First, a validation error will be displayed in the markup page. Second, when you try to run the application, you will get an exception page because the system was not able to do the necessary conversion.

What is the problem with the following code snippet? try { // call the database for information } catch(Exception ex) { // handle the exception } catch (ArgumentNullException ex) { // handle the exception }"

When you have multiple catch statements, the framework evaluates the exception against the catch parameters in order from the top down. Because it takes this approach, you need to ensure that the most general exception is at the bottom of the list. In this case, no exception will ever hit the second catch block because they all would be caught by the generic, first catch block.

Is it possible to put validation on a model in such a way that a model can never be valid?

Yes, it is certainly possible to set up a scenario in which a model can never be valid. Even ruling out such obvious errors as using a "less than" when you should have used a "greater than," it is easy to set up these kinds of cases, especially when using validation approaches that compare the values of one controller to another. If you followed the suggestion of ensuring that you always have a valid and complete message, then you should be able to understand and manage scenarios in which you have validated yourself into a corner.

The ASP.NET MVC template displays a model in a certain format. Is it possible to do the same thing in an ASP.NET Web Forms application?

Yes, you can use a user control to solve the same kind of problem. While you will not get the automatic translation for DisplayFor or EditorFor, that's OK because neither concept is supported in the ASP.NET Web Forms world. You would instead create a user control that has a parameter of the model, or object, that you wanted to display. The code-behind could take that object and do the necessary work, whether it is simply displaying the item or doing business logic with that item. While the instantiation of the control is slightly more awkward, you can create a user control that is very similar to an MVC template.

Can you use trace or logging to get an understanding of your application's performance?

You can use either tracing or logging to provide information about anything going on within your application. This includes the capability to add tracing and/or logging code that will provide information about the time spent in each method. One approach would be to use code such as the following: public ActionResult Details(string id) { DateTime enterDate = DateTime.Now; // do lots of work that could take a long time string message = string.Format( "Details methods took {0} milliseconds", (DateTime.Now - enterDate).Milliseconds); System.Diagnostics.Trace.TraceInformation(message); return View(); }

When you want to get a partial view that has been processed on the server, when do you not have to pass the controller into the Html.Action method?

You do not have to include the controller name in an Html.Action method call when the action that you are calling is on the same controller. If the action is on a different controller, you need to ensure that you include the appropriate controller name.

What would you have to do differently if you wanted to put the functionality from the last activity, for store hours, on an ASP.NET Web Forms page?

You would not have to do anything different as long as you added both the same <div> tags and scripting. This will work regardless of the type of ASP.NET that you used to create the page as long as all of the proper elements are within the page.


Ensembles d'études connexes

Chapter 18: AIDS and Other Immune Disorders

View Set

ECON 2106 Chapter 6: Supply, Demand, & Gov. Policies

View Set

Emotional Intelligence Final Exam

View Set

Bio Practice Questions and Answers 2

View Set

Unit 9 - International Economics

View Set

ATI Fundamentals B Practice - stu

View Set

Combined Class- Maternity Evolve- Part 2

View Set

Chp 6 - Web Development & Design Foundations with HTML 5

View Set