Knowledge Conclusion - PART I: ASP.NET

30 篇文章 0 订阅
6 篇文章 1 订阅

/*****by Jiangong SUN*****/


PART I : ASP.NET

Update 30/05/2013, 09/07/2013

1) What are the differences among Session, Cookie, Cache and ViewState? When do you use them ?
Answer:
Session is stored in Server side. Session could add the server load, it will lose data when page is closed, it's safe.


Get session:

HttpContext.Current.Session[key];

Add session:
HttpContext.Current.Session.Add(key, value);

Set session:
HttpContext.Current.Session[key] = value;

Remove session:
HttpContext.Current.Session.Remove(key);

Cookie is stored in Client side. Cookie can be cheated so it's not safe.
Cookie can maintain user's data in client side for preventing input login information. Session can authenticate users in the server side.


Usage: use Response for writing cookie, and use request for reading cookie.


Get cookie:
HttpContext.Current.Request.Cookies[name];

Add cookie:
HttpCookie aCookie = new HttpCookie(COOKIE_NAME);
aCookie.Values[COOKIE_LANGUAGE] = cultureCode;
aCookie.Expires = DateTime.Now.AddYears(10);
HttpContext.Current.Response.Cookies.Add(aCookie);

Remove cookie: 
No direct code to do that, you can save cookie with a passed time.
aCookie.Expires = DateTime.Now.AddMinutes(-1);

If objects are shareable between user sessions, then use cache. It can prevent loading the resources repeatedly in a short time.
ViewState is available in a single page, once the page is submitted it will be cleared. It can store hidden input and persist control's state after postbacks.


Two caching mechanisms are: application caching, page output caching.
application caching saves data in server memory and require extensive server resources to create. It can prevent of recreating information.
page output caching stores the generated output of pages, controls, and HTTP responses in memory.


Get cache:
HttpContext.Current.Cache[key];

Add cache: 
HttpContext.Current.Cache.Add(key.ToString(), cachedItem, null, DateTime.Now.AddMinutes(CST_CACHE_DURATION), Cache.NoSlidingExpiration, CacheItemPriority.High, null);

or use insert:
HttpContext.Current.Cache.Insert("DSN", connectionString);

Set cache :
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

NoCache   Specifies that the device making the request should get the response from the Web server each time.
Public    Allows the response to be cached by clients and shared (proxy) caches.
Private   Specifies that the response is cacheable only on the client and not by shared (proxy server) caches.
Server    Specifies that the response is cached only at the origin server.
ServerAndNoCache   Applies the settings of both Server and NoCache to indicate that the content is cached at the server but all others are explicitly denied the ability to cache the response.
ServerAndPrivate   Specifies that a response should be cached only on the origin server and on the requesting client; proxy servers are not allowed to cache the response.
Remove cache:
HttpContext.Current.Cache.Remove(key.ToString());

Session vs Cookie: Session is stored in server; Cookie is stored in client.

Session vs Cache: Session is for per user; Cache is for all users

Session vs ViewState: Session is for application; ViewState is for one specific page.

2) What is asp.net page life cycle ?
Answer:
SILVER: Start, Init, Load, Validation, Event, Render, Unload


3) What is the difference between HttpHandler and HttpModule ?

Answer:

When a request come to asp.net application, it's firstly processed by multiple modules(authentication module, session module), then by a single handler, and then flow back to modules.

Custom modules must implement the System.Web.IHttpModule interface. 
Custom handlers must implement the System.Web.IHttpHandler interface.

Modules are used in application level

Handlers are used in page level

reference: http://geekswithblogs.net//flanakin/articles/ModuleHandlerIntro.aspx


4) QueryString?

QueryString is a collection for retrieve the information from HTTP query string. 

Example:

http://jiangong.com?firstname=jiangong&lastname=sun

string firstName = Request.QueryString("firstname");


5) Web control vs. User control

UserControl: A custom control, ending in .ascx, that is composed of other web controls. Its almost like a small version of an aspx webpage. It consists of a UI (the ascx) and codebehind. Cannot be reused in other projects by referencing a DLL.

WebControl: A control hosted on a webpage or in a UserControl. It consists of one or more classes, working in tandem, and is hosted on an aspx page or in a UserControl. WebControls don't have a UI "page" and must render their content directly. They can be reused in other applications by referencing their DLLs.

reference:

http://stackoverflow.com/questions/71092/what-is-the-difference-between-usercontrol-webcontrol-renderedcontrol-and-comp


5) What is the difference between ASP.NET MVC1, MVC2, MVC3, MVC4?

MVC2: 

HTML element helper like Html.TextBoxFor(), Html.TextAreaFor() in addition to Html.TextBox() and Html.TextAreaFor()

Support for rendering sub-sections of a page/site using Html.RenderAction

MVC3: 

Razor view engine in addition to ASPX view engine

Unobtrusive Ajax and unobtrusive client side validation

<form action="/ajax/callback" id="form0" method="post" οnclick="Sys.Mvc.AsyncForm.handleClick(this,new Sys.UI.DomEvent(event));"

    οnsubmit="Sys.Mvc.AsyncForm.handleSubmit(this,new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace,loadingElementId: 'loading', updateTargetId: 'updateme' });"> 

<form action="/ajax/callback" data-ajax="true" data-ajax-loading="#loading"  data-ajax-mode="replace"  data-ajax-update="#updateme" method="post">

MVC4: 

Use the HTML5 viewport attribute and CSS media queries to improve the display on mobile devices
Use jQuery Mobile for progressive enhancements and for building touch-optimized web UI
Create asynchronous controllers using task support

New template for desktop and mobile 
Authentication OpenID, OAuth
Separation of controllers into different folders
Default IIS Express for applications
Different display for different user agent, ex: Iphone, Ipad etc
Bundling: combine multiple files into one
Integrate multiple files to App_Start\BundleConfig.cs 
Minification: Delete useless space of files


6) What's the difference between ASP.NET and ASP.NET MVC?

ASP.NET:

ViewState


ASP.NET MVC:

Unit test

Model-view-controller

Stateless

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
10:35:56.822 Module build failed (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/sass-loader/dist/cjs.js): 10:35:56.830 SassError: Undefined variable: "$u-form-item-height". 10:35:56.830 on line 210 of D:\ideaWorkSpace\ehl-wx\applicationCenter\knowledgeBase\addQuestion.vue 10:35:56.839 >> line-height: $u-form-item-height; 10:35:56.848 ------------------^ 10:35:56.856 Module build failed (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/sass-loader/dist/cjs.js): 10:35:56.863 SassError: Undefined variable: "$u-form-item-height". 10:35:56.873 on line 220 of D:\ideaWorkSpace\ehl-wx\applicationCenter\examine\answerQuestion.vue 10:35:56.873 >> line-height: $u-form-item-height; 10:35:56.880 --------------------^ 10:35:56.880 Module build failed (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/sass-loader/dist/cjs.js): 10:35:56.889 SassError: Undefined variable: "$u-form-item-height". 10:35:56.896 on line 220 of D:\ideaWorkSpace\ehl-wx\applicationCenter\knowledgeBase\answerQuestion.vue 10:35:56.903 >> line-height: $u-form-item-height; 10:35:56.904 --------------------^ 10:35:56.913 Module build failed (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/sass-loader/dist/cjs.js): 10:35:56.913 SassError: Undefined variable: "$u-form-item-height". 10:35:56.921 on line 232 of D:\ideaWorkSpace\ehl-wx\applicationCenter\examine\addQuestion.vue 10:35:56.930 >> line-height: $u-form-item-height; 10:35:56.930 ------------------^ 10:35:56.938 Module build failed (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/sass-loader/dist/cjs.js): 10:35:56.938 SassError: Undefined variable: "$u-form-item-height". 10:35:56.946 on line 350 of D:\ideaWorkSpace\ehl-wx\pages\service\addService.vue 10:35:56.947 >> line-height: $u-form-item-height; 10:35:56.954 -------------------^解决
最新发布
07-14

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值