Response.Redirect() vs Server.Transfer()

Response.Redirect() should be used when:

  • we want to redirect the request to some plain HTML pages on our server or to some other web server
  • we don’t care about causing additional roundtrips to the server on each request
  • we do not need to preserve Query String and Form Variables from the original request
  • we want our users to be able to see the new redirected URL where he is redirected in his browser (and be able to bookmark it if its necessary)

Server.Transfer() should be used when:

  • we want to transfer current page request to another .aspx page on the same server
  • we want to preserve server resources and avoid the unnecessary roundtrips to the server
  • we want to preserve Query String and Form Variables (optionally)
  • we don’t need to show the real URL where we redirected the request in the users Web Browser

enter image description here

Application, Session, Request, Response and HttpCookie

Application: 

System.Web.HttpContext.Current.Application[“Name”] = “Value”;
System.Web.HttpContext.Current.Application[“AppDB”] = “Remote USA”;

Session and Request:

Session[“RequestURL”] = Request.Url.ToString();

Response and HttpCookie:

A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site.

HttpCookie cookie = new HttpCookie(“Cookie”);
cookie.Value = “Hello Cookie! CreatedOn: ” + DateTime.Now.ToShortTimeString();
//this.ControllerContext.HttpContext.Response
this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
if(this.ControllerContext.HttpContext.Request.Cookies.AllKeys.Contains(“Cookie”))
{
HttpCookie cookie = this.ControllerContext.HttpContext.Request.Cookies[“Cookie”];
cookie.Expires = DateTime.Now.AddDays(-1);
//this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
this.ControllerContext.HttpContext.Response.Cookies.Remove(“Cookie”);
}

Web Programming Using the Razor Syntax (C#)

Follow this link for razor syntax. Introducing Razor Syntax

The @ character starts inline expressions, single statement blocks, and multi-statement blocks:

Sample Code for:

@: [some text]

<text>some text</text>

@{
    var greeting = "Welcome to our site!";
    var weekDay = DateTime.Now.DayOfWeek;
    var greetingMessage = greeting + " Today is: " + weekDay;
}
<p>Today's weather: @weatherMessage</p>
<!-- Embedding a backslash in a string -->
@{ var myFilePath = @"C:\MyFolder\"; }
<p>The path is: @myFilePath</p>
@if(IsPost) {
    // This line has all content between matched <p> tags.
    <p>Hello, the time is @DateTime.Now and this page is a postback!</p>
} else {
    // All content between matched tags, followed by server code.
    <p>Hello <em>stranger</em>, today is: <br /> </p>  @DateTime.Now
}
@{
    @* This is a comment. *@
    var theVar = 17;
}

Models, Views, and Controllers

What does MVC look like?

MVC look like

All Posts MVC look like

URL Patterns

Result Type

for detail check this link

https://msdn.microsoft.com/en-us/library/system.web.mvc.actionresult(v=vs.118).aspx

MVC Applications

•Models encapsulate objects and data
•Views generate the user interface
•Controllers interact with user actions
•Code in .cshtml and .cs files
•ViewBag
–Dynamic object for storing basic pieces of information
•Alias for ViewData
–Perfect for sending messages to the view
–Only available for that action
•Redirects cause the ViewBag to be emptied
TempData
–Just like the ViewBag, but it’s also available on the next page
We can save date

like this

viewData[“myobj”]=myobj

here “myobj” is the keyword in the deictionary and the object it is holding
against it is myobj and receive it like this in view

var auction = (mvcauction.models.myobj)ViewData[“myobj”]

it is receiving it not as a strongly typed object in fact as a object type and has to caste it in view we can use viewbag method to avoid it and receive object as  strongly typed object
like this

var myobj=viewbag.myobj

we can use better method by passing model like
return view(myobj);

var myobj=Model

MVC is a stateless architecture if u need to redirect user to another
request/action and giving him message of successful completion
tempdata is both exposed to controller and view tempdata is stored on server for exactly one request from the user if u assign data to it on one request it would be available to very next request

Action Name
Attributes