0% found this document useful (0 votes)
22 views10 pages

Web

The document outlines various HTTP response codes, authentication and authorization filters, action filters, and session-state modes in ASP.NET. It also covers MVC architecture, AJAX methods, HTML helpers, output caching, bundling, and state management techniques like view state and cookies. Additionally, it explains how to manage session data in MVC applications using TempData, ViewData, and ViewBag.

Uploaded by

guruguru2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views10 pages

Web

The document outlines various HTTP response codes, authentication and authorization filters, action filters, and session-state modes in ASP.NET. It also covers MVC architecture, AJAX methods, HTML helpers, output caching, bundling, and state management techniques like view state and cookies. Additionally, it explains how to manage session data in MVC applications using TempData, ViewData, and ViewBag.

Uploaded by

guruguru2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Response Code Series

100
Informational --Continue and processing.
200
Success--Response Successful, no action required, Ok Status
300
Redirection--Need more action to fulfill the request.
400
Client Error--The Request contains unknown syntax and server did not fulfill the
request.
500
Server Error--The Server failed to fulfill the valid request.

200 OK
300 Multiple Choices
301 Moved Permanently
302 Found
304 Not Modified
307 Temporary Redirect
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
410 Gone
500 Internal Server Error
501 Not Implemented
503 Service Unavailable
550 Permission denied

Authentication Filters

Authentication filter runs before any other filter or action method. Authentication
confirms that you are a valid or invalid user.
Action filters implement the IAuthenticationFilter interface.

Authorization Filters

The AuthorizeAttribute and RequireHttpsAttribute are examples of Authorization


Filters.
Authorization Filters are responsible for checking User Access; these implement the
IAuthorizationFilterinterface in the framework.
These filters used to implement authentication and authorization for controller
actions. For example, the Authorize filter is an example of an Authorization
filter.

Action Filters

Action Filter is an attribute that you can apply to a controller action or an


entire controller.
This filter will be called before and after the action starts executing and after
the action has executed.

Action filters implement the IActionFilter interface that has two methods
OnActionExecuting andOnActionExecuted.
OnActionExecuting runs before the Action and gives an opportunity to cancel the
Action call.
These filters contain logic that is executed before and after a controller action
executes, you can use an action filter, for instance,
to modify the view data that a controller action returns.
Result Filters

The OutputCacheAttribute class is an example of Result Filters.


These implement the IResultFilter interface which like the IActionFilter has
OnResultExecuting and OnResultExecuted.
These filters contain logic that is executed before and after a view result is
executed. Like if you want to modify a view result right before the view is
rendered to the browser.

ExceptionFilters

The HandleErrorAttribute class is an example of ExceptionFilters.


These implement the IExceptionFilter interface and they execute if there are any
unhandled exceptions thrown during the execution pipeline.
These filters can be used as an exception filter to handle errors raised by either
your controller actions or controller action results.

Session-State modes are 5 type:


InProc mode: which stores session state in memory on the Web server. This is the
default.
StateServer mode: which stores session state in a separate process called the
ASP.NET state service. This ensures that session state is preserved
if the Web application is restarted and also makes session state available
to multiple Web servers in a Web farm.
SQLServer mode stores session state in a SQL Server database. This ensures that
session state is preserved if the
Web application is restarted and also makes session state available to
multiple Web servers in a Web farm.
Custom mode: which enables you to specify a custom storage provider.
Off mode: which disables session state.

There are three kinds of session, and they are listed as follows
Inprocess.
Outprocess.
Sql server session.

where they are stored.


inproc - default stored in web.config.
outproc - stored in server side.
Sql server - stored in database.
You have following types of session management in asp.net which you can define in
your web.config file

Session mode="inproc"...means the session will be stored on the webserver within


your application
session mode="outproc"....means session will be stored on the server outside your
application
session mode="stateserver"...means session will be stored in a temporary memory in
the database
session mode="sqlserver"...means session will be stored in the database
permanently.

Mvc architecture
Models-Represents the data
View -display the data into the user
Controller- handle the request and send response to the appropriate view
Mvc life cycle:
Two steps here first of understanding the type of request and return the responses
to appropriate view .
Second step:Creating the request object and sending to the browser.

Map:
This�map()�Method in jQuery is used to translate all items in an array or object to
new array of items.

grep():
This grep() method in jQuery is used to finds the elements of an array that
satisfies a filter function.not affected in original array.
Syntax:
jQuery.grep(array, function(element, index) [, invert])
array:�This parameter holds the array like object for searching.
function(element, index):�It is the filter function which takes two
arguments,�element�which holds the element of the array and�index�which holds the
index of that particular element.
invert:�It is false or not passed, then the function returns an array having all
elements for which �callback� returns true.
If this is passed true, then the function returns an array having all elements for
which �callback� returns false.
Filter:
The filter()�method is used to filter out all the elements that do not match the
selected criteria and those matches will be returned.
Syntax:
$(selector).filter(criteria, function(index))

Ajax:
Used to load the data from server side without browser page refresh.
Ajax Syntax:

async:--Set to false if the request should be sent synchronously. Defaults to true.


type:-- HTTP Request and accepts a valid HTTP verb.
url:--URL for the request.
data:--The data to be sent to the server. This can either be an object or a query
string.
contentType:--content type of the request you are making. The default is
'application/x-www-form-urlencoded'.
datatype:By default, jQuery will look at the MIME type of the response if no
dataType is specified.Accepted values are text, xml, json, script, html jsonp.
success:--The function receives the response data (converted to a JavaScript object
if the DataType was JSON),
as well as the text status of the request and the raw request object.
error:--A callback function to run if the request results in an error. The function
receives the raw request object and the text status of the request.

$.ajax({
type: "POST",
url: "/Home/JqAJAX",
data: JSON.stringify(Student),
dataType: "json"
contentType: 'application/json; charset=utf-8',
success: function(data) {
alert(data.msg);
},
error: function() {
alert("Error occured!!")
}
});

MasterLayout page:
its Located at Shared folder in MVC APPlication
you learn how to create a common page layout for multiple pages in your application
by taking advantage of view master pages
You also can take advantage of view master pages to share common content across
multiple pages in your application.
For example, you can place your website logo, navigation links, and banner
advertisements in a view master page.
That way, every page in your application would display this content automatically

Ajax Method :Asynchronous Javascript And XML


--ajax() method is used to perform an AJAX (asynchronous HTTP) request.
$.ajax() Performs an async AJAX request.
$.get() Loads data from a server using an AJAX HTTP GET request.
$.post() Loads data from a server using an AJAX HTTP POST request

$.ajax () Method Configuration option:


async:its default true , set to the false request Synchronusly.
type: here we have used in the form of http verbs --> GET,POST
url:Url for the Request -->(Controller , Action method ) or Directly used to URL
data:Data can be sent to the server its Object or Query String .
datatype:--text, xml, json, script, html jsonp.
contenttype:content type of the request you are making--by default (application/x-
www-form-urlencoded)
success:
error:
<script type="text/javascript">
$(document).ready(function() {
$(function() {
$('#btnSubmit').click(function(event) {
event.preventDefault();
var Student = {
ID: '10001',
Name: 'Shashangka',
Age: 31
};
$.ajax({
type: "POST",
url: "/Home/JqAJAX",
data: JSON.stringify(Student),
dataType: "json"
contentType: 'application/json; charset=utf-8',
success: function(data) {
alert(data.msg);
},
error: function() {
alert("Error occured!!")
}
});
});
});
});
</script>
Grep:
--------
jQuery.grep( array, function [, invert ])
----------------------------------------------
Def:
grep() method in jQuery is used to finds the elements of an array that satisfies a
filter function.
Array:
--Type:ArrayLikeObject
--Searchigh the Object
function :
Function (Object elementOfArray,integer Indexof Array)=>Boolean
--Here the first argument of the fuction in sitem ,second one index of the item .
invert:
--Invert is false--array consisting all elements for which call return is true.
--Invert is true--array consisting all elements for which call return is false.

jQuery.map(array,callback)
jQuery.map(object,callback)
Def:
map() Method in jQuery is used to translate all items in an array or object to new
array of items.

--array:Array to translate
--object:object to translate
--Callback:
callback(Object elementOfArray,integer Indexof Array)=>Boolean
callback: This parameter holds the function to process each item against.

// The following object masquerades as an array.


var fakeArray = { "length": 2, 0: "Addy", 1: "Subtracty" };

// Therefore, convert it to a real array


var realArray = $.makeArray( fakeArray )

// Now it can be used reliably with $.map()


$.map( realArray, function( val, i ) {
// Do something
});

jQuery Array.Map
Note: map() does not execute the function for array elements without values.
Note: this method does not change the original array.

Filter:$(selector).filter(criteria, function(index))
Def:
filter() method is used to filter out all the elements that do not match the
selected criteria and those matches will be returned.
<html>

<head>
<title>GEEKS FOR GEEKS ARTICLE</title>
<script src="https://ajax.googleapis.com/ajax/libs/
jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("li").filter(".first, .last").css("color", "red")
.css("backgroundColor", "yellow");
});
</script>
</head>
<body>
<ul>
<li class="first">GeeksForGeeks</li>
<li class="first">GeeksForGeeks</li>
<li class="middle">GeeksForGeeks</li>
<li class="last">GeeksForGeeks</li>
<li class="last">GeeksForGeeks</li>
</ul>
</body>

</html>

HTML Helpres :
--Just Like a Web Forms control in ASP.Net,HTML Helpers used to modify HTML
Page ,it is morlight weight
In Most of the method HTML helpers return as string, In MVC you can create own HTML
Helpers or Use Built in HTML helpers

Standard HTML Helper:


Purpose:used to render the most common type of HTML controls like Label,TextBox,
Password,
TextArea, CheckBox, RadioButtion, DropDownList, Listbox,Display,Editor and
ActionLink
@Html.ActionLink() - Used to create link on html page
@Html.TextBox() - Used to create text box
@Html.CheckBox() - Used to create check box
@Html.RadioButton() - Used to create Radio Button
@Html.BeginFrom() - Used to start a form
@Html.EndFrom() - Used to end a form
@Html.DropDownList() - Used to create drop down list
@Html.Hidden() - Used to create hidden fields
@Html.label() - Used for creating HTML label is on the browser
@Html.TextArea() - The TextArea Method renders textarea element on browser
@Html.Password() - This method is responsible for creating password input field on
browser
@Html.ListBox() - The ListBox helper method creates html ListBox with scrollbar on
browser

Strongly Typed HTML Helpers:


Purpouse:
All strongly-typed HTML helpers depend on the model class. We can create this
using a lambda expression of extension method of HTML helper class
@Html.HiddenFor()
@Html.LabelFor()
@Html.TextBoxFor()
@Html.RadioButtonFor()
@Html.DropDownListFor()
@Html.CheckBoxFor()
@Html.TextAreaFor()
@Html.PasswordFor()
@Html.ListBoxFor()

List of Templated HTML Helpers


Purpouse:
When we use an HTML helper method, such as LabelFor() or TextBoxFor(), then it
displays the model property in a fixed manner. .
.. Similarly, the TextBoxFor() HTML Helper method renders a textbox in which
the model property value is shown for editing
@Html.Display()
@Html.DisplayFor()
@Html.DisplayName()
@Html.DisplayNameFor()
@Html.DisplayText()
@Html.DisplayTextFor()
@Html.DisplayModelFor()
Edit / Input:
@Html.Editor()
@Html.EditorFor()
@Html.EditorForModel()

Ouput Cache:
We need caching in many different scenarios to improve the performance of an
application
Purpouse:
you can take advantage of the output cache to avoid executing a database query
every time a user invokes the same controller action.
In this case, the view will be retrieved from the cache instead of being
regenerated from the controller action.
Caching enables you to avoid performing redundant work on the server

[OutputCache(Duration = 60)]
public ActionResult Index(){
var employees = from e in db.Employees
orderby e.ID
select e;
return View(employees);
}

Bundling :
Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle
multiple files into a single file.
You can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP
requests and that can improve first page load performance
Bundling and Minification provide us a way to both reduce the number of requests
needed to get JS and CSS resource files and reduce the size of the files
themselves,
thereby improving the responsiveness of our apps.
Purpouse:
They are nice little optimizations for our MVC apps that can improve performance
and add responsiveness.

we call WCF service from Javascript?


It's very easy, you have to pass url with method, parameter (value from textbox)
specify data type and callback function. Now you can run webapplication,
put some text in input box and press button �jQuery call� Calling WCF service with
Microsoft Ajax is much more easy.
View state:
View state is the page-level state management technique used in the ASP.NET page
framework to retain the value of controls and page between round trips.
Data objects such as hash tables, strings, array objects, array list objects,
Boolean values and custom-type converters can be stored in view state.
ViewModel:
ViewModel is a class that contains the fields which are represented in the
strongly-typed view. It is used to pass data from controller to strongly-typed view
View state is ideally used when the data to be preserved is relatively small and
the data need not be secured.
session state:
In ASP.NET session is a state that is used to store and retrieve values of a user.
It helps to identify requests from the same browser during a time period (session).
It is used to store value for the particular time session. By default, ASP.NET
session state is enabled for all ASP.NET applications.
Purpouse: Avoiding DB hits, For Ex: Availablity Modify Search with same details ,
that time we have fetched availablity from Session with help of Session ID
Cookies :
Cookies are one of the State Management techniques, so that we can store
information for later use.
Cookies are small files that are created in the web browser's memory (if they're
temporary) or on the client's hard drive (if they're permanent)

Types Of Action FIlters:


void OnActionExecuted(ActionExecutedContext filterContext)-- It is called just
after the action method is called.
void OnActionExecuting(ActionExecutingContext filterContext)--It is called just
before the result is executed; it means before rendering the view.

void OnResultExecuted(ResultExecutedContext filterContext)--It is called just after


the result is executed, it means after rendering the view.
void OnResultExecuting(ResultExecutingContext filterContext)--Called before the
action result that is returned by an action method is executed.

Purpouse: OnResultExecuted and OnResultExecuting


which can be used to execute custom logic before or after the result executes.

session :
MVC the controller decides how to render view, meaning which values are accepted
from View and which needs to be sent back in response.
ASP.NET MVC Session state enables you to store and retrieve values for a user when
the user navigatesto other view in an ASP.NET MVC application.

Purpouse:
MVC provides three ways (TempData, ViewData and ViewBag) to manage session, apart
from that we can use session variable, hidden fields and HTML controls for the
same.
But like session variable these elements cannot preserve values for all requests;
value persistence varies depending the flow of request.
session Storage Format:
Session stores the data in key and value format. Value gets stored in object
format, so any type of data (string, integer, class collection etc.)

Session-State modes are 5 type:


InProc mode:
which stores session state in memory on the Web server. This is the default.
StateServer mode:
which stores session state in a separate process called the ASP.NET state service.
This ensures that session state is preserved if the Web application is restarted
and also makes session state available to multiple Web servers in a Web farm.
SQLServer mode:
SQLServer modestores session state in a SQL Server database.
This ensures that session state is preserved if the Web application is restarted
and also makes session state available to multiple Web servers in a Web farm.
Custom mode: which enables you to specify a custom storage provider.
Off mode: which disables session state.
Action filters are generally used to apply cross-cutting concerns such as logging,
caching, authorization, etc
Scaffolding:
Scaffolding is a technique used by many MVC frameworks like ASP.NET MVC, Ruby on
Rails, Cake PHP and Node. JS etc.
to generate code for basic CRUD (create, read, update, and delete) operations
against your database effectively.
Further you can edit or customize this auto generated code according to your need

Routing :
Def:Routing is a mechanism in MVC that decides which action method of a controller
class to execute.
Without routing there's no way an action method can be mapped. to a request.
Routing is a part of the MVC architecture so ASP.NET MVC supports routing by defaul
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Student",
url: "students/{id}",
defaults: new { controller = "Student", action = "Index"}
);
Web API Routing:
Web API routing is similar to ASP.NET MVC Routing. It routes an incoming HTTP
request to a particular action method on a Web API controller.
Web API supports two types of routing: Convention-based Routing. Attribute Routing.
public static void Register(HttpConfiguration config)
{
// Enable attribute routing
config.MapHttpAttributeRoutes();

// Add default route using convention-based routing


config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Error Handling Types in MVC :
Web.Config customErrors
MVC HandleErrorAttribute
Controller.OnException method
HttpApplication Application_Error event
Collect exceptions via .NET profiling with Retrace

Enabling a WCF Transaction


Step 1-Creation of two WCF Services. ...
Step 2- Method creation and its attribution with TransactionFlow attribute
Step 3-Implementation of WCF service with TransactionScopeRequired attribute.
Step 4-Enabling Transaction Flow by WCF Service Config File.

Transaction Properties of WCF


Atomic:
All the operations must act as a single indivisible operation at the completion of
a transaction
Consistency:
Whatever may be the operation set, the system is always in a state of consistency,
i.e., the outcome of the transaction is always as per the expectation.
Isolation :
The intermediary state of system is not visible to any entities of the outer world
till the transaction is completed.
Durablity:
Committed state is maintained regardless of any kind of failure (hardware, power
outage, etc.)
LINQ:
Standardized way of querying multiple data sources: The same LINQ syntax can be
used to query multiple data sources.
Compile time safety of queries: It provides type checking of objects at compile
time.
Readable code: LINQ makes the code more readable so other developers can easily
understand and maintain it
Types
LINQ to Objects.
LINQ to XML(XLINQ)
LINQ to DataSet.
LINQ to SQL (DLINQ)
LINQ to Entities.

You might also like