Rectangle 27 50

Alternative with minimist

var gulp   = require('gulp');

// npm install gulp yargs gulp-if gulp-uglify
var args   = require('yargs').argv;
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');

var isProduction = args.env === 'production';

gulp.task('scripts', function() {
  return gulp.src('**/*.js')
    .pipe(gulpif(isProduction, uglify())) // only minify if production
    .pipe(gulp.dest('dist'));
});
// npm install --save-dev gulp gulp-if gulp-uglify minimist

var gulp = require('gulp');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');

var minimist = require('minimist');

var knownOptions = {
  string: 'env',
  default: { env: process.env.NODE_ENV || 'production' }
};

var options = minimist(process.argv.slice(2), knownOptions);

gulp.task('scripts', function() {
  return gulp.src('**/*.js')
    .pipe(gulpif(options.env === 'production', uglify())) // only minify if production
    .pipe(gulp.dest('dist'));
});
gulp scripts --env production

That recipe link seems gone now. There is another one that uses the minimist package instead: pass-arguments-from-cli.md. That makes sense since gulp itself uses minimist.

javascript - Is it possible to pass a flag to Gulp to have it run task...

javascript node.js gulp
Rectangle 27 25

Yes there is: it's called view models. View models are classes which are specifically tailored to the specific needs of a given view.

public ActionResult Index([Bind(Exclude = "Id")] SomeDomainModel model)
public ActionResult Index(SomeViewModel viewModel)

where the view model contains only the properties which need to be bound. Then you could map between the view model and the model. This mapping could be simplified with AutoMapper.

As best practice I would recommend you to always use view models to and from a view.

+1 This is the best description ever that I've seen about ViewModel vs Business model. I've never thought about it from a security point of view. But's is the reason to use a view model, at least for http.

@Rookian, yes it is a good practice to have separate view models.

@Darin: so when you have a big, complex graph of domain objects with many properties (and relationships, validation rules, etc.) that needs to be presented on a form, do you redefine all of the relevant properties in your view models, manually copy all the properties between them, etc.? It seems like this would result in lots of duplication, hard dependencies and redundant code, so I've been avoiding it like the plague - even though it seems like the "correct" approach, in practice I don't see how you would get around all the awkward duplication and repetition..??

@mindplay.dk, I put all that's needed in the view model. If my initial domain model has some complex graph of properties I might flatten it. But once again I include only what I need to show/edit in the view. If it is just for persisting some data into hidden fields (ViewState sorta emulation) then I don't include those properties in the view model. I include only the id that will allow me to fetch this information back from wherever it is stored. And as far as the manual copying is concerned, no, I don't do anything manually, I use AutoMapper which does this for me.

@Darin: but you are duplicating all those properties from your domain-model that are required in the view, correct? What about validation annotations, do you duplicate all of those, or do you only have the validation annotations on the view-models? (thanks for sharing!)

c# - ASP.NET MVC - Alternative for [Bind(Exclude = "Id")] - Stack Over...

c# asp.net-mvc-2 modelbinders
Rectangle 27 2

"Note that changes to B must be coherent with other projects depending on B, which are not all ASP.NET project"

Not sure what coherent would mean to you in context of other projects which depend on project B... But following options come to mind -

I did not use Resources, but Assembly (and I had to stay within the same class). See stackoverflow.com/a/2041057/1287856

asp.net - Alternative to FileStream in C# .NET - Stack Overflow

c# asp.net .net filestream
Rectangle 27 2

Ensure that data.txt is being deployed somewhere. Then, make your library take the path to it or the base directory path as an argument. The caller of the library is the application which has concrete knowledge of how to obtain the file's path.

Or, embed the .txt into the DLL as a manged resource.

asp.net - Alternative to FileStream in C# .NET - Stack Overflow

c# asp.net .net filestream
Rectangle 27 25

Yes there is: it's called view models. View models are classes which are specifically tailored to the specific needs of a given view.

public ActionResult Index([Bind(Exclude = "Id")] SomeDomainModel model)
public ActionResult Index(SomeViewModel viewModel)

where the view model contains only the properties which need to be bound. Then you could map between the view model and the model. This mapping could be simplified with AutoMapper.

As best practice I would recommend you to always use view models to and from a view.

+1 This is the best description ever that I've seen about ViewModel vs Business model. I've never thought about it from a security point of view. But's is the reason to use a view model, at least for http.

@Rookian, yes it is a good practice to have separate view models.

@Darin: so when you have a big, complex graph of domain objects with many properties (and relationships, validation rules, etc.) that needs to be presented on a form, do you redefine all of the relevant properties in your view models, manually copy all the properties between them, etc.? It seems like this would result in lots of duplication, hard dependencies and redundant code, so I've been avoiding it like the plague - even though it seems like the "correct" approach, in practice I don't see how you would get around all the awkward duplication and repetition..??

@mindplay.dk, I put all that's needed in the view model. If my initial domain model has some complex graph of properties I might flatten it. But once again I include only what I need to show/edit in the view. If it is just for persisting some data into hidden fields (ViewState sorta emulation) then I don't include those properties in the view model. I include only the id that will allow me to fetch this information back from wherever it is stored. And as far as the manual copying is concerned, no, I don't do anything manually, I use AutoMapper which does this for me.

@Darin: but you are duplicating all those properties from your domain-model that are required in the view, correct? What about validation annotations, do you duplicate all of those, or do you only have the validation annotations on the view-models? (thanks for sharing!)

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

c# - ASP.NET MVC - Alternative for [Bind(Exclude = "Id")] - Stack Over...

c# asp.net-mvc-2 modelbinders
Rectangle 27 6

From experience, ViewState has the biggest impact on performance of UpdatePanels and AJAX in general, since each time there is a round trip all data in the ViewState must be serialized and packaged up into XmlHttpRequest(s) and sent across the wire.

In general, I would agree with others that it seems like AJAX may not be your only issue. You may want to profile the application and database performance to ensure your focusing in the right area.

The biggest factor was the updateMode, all update panels where always been sent back to the server, which is pretty much the entire page!

ajax - alternative for asp.net updatePanels - Stack Overflow

asp.net ajax updatepanel
Rectangle 27 6

From experience, ViewState has the biggest impact on performance of UpdatePanels and AJAX in general, since each time there is a round trip all data in the ViewState must be serialized and packaged up into XmlHttpRequest(s) and sent across the wire.

In general, I would agree with others that it seems like AJAX may not be your only issue. You may want to profile the application and database performance to ensure your focusing in the right area.

The biggest factor was the updateMode, all update panels where always been sent back to the server, which is pretty much the entire page!

ajax - alternative for asp.net updatePanels - Stack Overflow

asp.net ajax updatepanel
Rectangle 27 104

Initially I had recommended that you should simply replace all of your calls to [Response.End] with [...] CompleteRequest() calls, but if you want to avoid postback processing and html rendering you'll need to add [...] overrides as well.

The Server.Transfer, Response.Redirect, Response.End methods all raise exceptions. Each of these methods internally call Response.End. The call to Response.End, in turn, causes a ThreadAbortException exception.

create a class level variable that flags if the Page should terminate and then check the variable prior to processing your events or rendering your page. [...] I would recommend just overriding the RaisePostBackEvent and Render methods

Response.End and Response.Close are not used in normal request processing when performance is important. Response.End is a convenient, heavy-handed means of terminating request processing with an associated performance penalty. Response.Close is for immediate termination of the HTTP response at the IIS/socket level and causes issues with things like KeepAlive.

The recommended method of ending an ASP.NET request is HttpApplication.CompleteRequest. Keep in mind that ASP.NET rendering will have to be skipped manually since HttpApplication.CompleteRequest skips the rest of the IIS/ASP.NET application pipeline, not the ASP.NET Page pipeline (which is one stage in the app pipeline).

Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event.

This method is provided only for compatibility with ASPthat is, for compatibility with COM-based Web-programming technology that preceded ASP.NET.preceded ASP.NET. [Emphasis added]

This method terminates the connection to the client in an abrupt manner and is not intended for normal HTTP request processing. [Emphasis added]

>Keep in mind that ASP.NET rendering will have to be skipped manually since HttpApplication.CompleteRequest skips the rest of the IIS/ASP.NET application pipeline, not the ASP.NET Page pipeline (which is one stage in the app pipeline). And how do you accomplish this?

See the link to the code where Jon Reid demonstrated how to set a flag and override the Page's RaisePostBackEvent and Render methods to skip the normal implementation when desired. (You'd probably do this in a base class all your app's pages should inherit from.) web.archive.org/web/20101224113858/http://www.c6software.com/

Just to restate: HttpApplication.CompleteRequest does not terminate the response as Response.End does.

HttpApplication.CompleteRequest also doesn't stop code flow, so subsequent lines keep running. That may not affect what the browser sees, but if those lines do any other processing, it can be really confusing.

I cannot think but that Web Forms is broken by design. What is more performance degrading, calling Response.End() or letting the page load everything and then suppress the response? I cannot see where Response.End() is "more" harmful here. Moreover, Microsoft treats `ThreadAbortedException' as a normal event as evident from this code: referencesource.microsoft.com/#System.Web/UI/Page.cs,4875 One thing that is against Response.End() is that it might fail aborting the response, which might result occasionally in the response being displayed.

.net - Is Response.End() considered harmful? - Stack Overflow

.net asp.net
Rectangle 27 104

Initially I had recommended that you should simply replace all of your calls to [Response.End] with [...] CompleteRequest() calls, but if you want to avoid postback processing and html rendering you'll need to add [...] overrides as well.

The Server.Transfer, Response.Redirect, Response.End methods all raise exceptions. Each of these methods internally call Response.End. The call to Response.End, in turn, causes a ThreadAbortException exception.

create a class level variable that flags if the Page should terminate and then check the variable prior to processing your events or rendering your page. [...] I would recommend just overriding the RaisePostBackEvent and Render methods

Response.End and Response.Close are not used in normal request processing when performance is important. Response.End is a convenient, heavy-handed means of terminating request processing with an associated performance penalty. Response.Close is for immediate termination of the HTTP response at the IIS/socket level and causes issues with things like KeepAlive.

The recommended method of ending an ASP.NET request is HttpApplication.CompleteRequest. Keep in mind that ASP.NET rendering will have to be skipped manually since HttpApplication.CompleteRequest skips the rest of the IIS/ASP.NET application pipeline, not the ASP.NET Page pipeline (which is one stage in the app pipeline).

Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event.

This method is provided only for compatibility with ASPthat is, for compatibility with COM-based Web-programming technology that preceded ASP.NET.preceded ASP.NET. [Emphasis added]

This method terminates the connection to the client in an abrupt manner and is not intended for normal HTTP request processing. [Emphasis added]

>Keep in mind that ASP.NET rendering will have to be skipped manually since HttpApplication.CompleteRequest skips the rest of the IIS/ASP.NET application pipeline, not the ASP.NET Page pipeline (which is one stage in the app pipeline). And how do you accomplish this?

See the link to the code where Jon Reid demonstrated how to set a flag and override the Page's RaisePostBackEvent and Render methods to skip the normal implementation when desired. (You'd probably do this in a base class all your app's pages should inherit from.) web.archive.org/web/20101224113858/http://www.c6software.com/

Just to restate: HttpApplication.CompleteRequest does not terminate the response as Response.End does.

HttpApplication.CompleteRequest also doesn't stop code flow, so subsequent lines keep running. That may not affect what the browser sees, but if those lines do any other processing, it can be really confusing.

I cannot think but that Web Forms is broken by design. What is more performance degrading, calling Response.End() or letting the page load everything and then suppress the response? I cannot see where Response.End() is "more" harmful here. Moreover, Microsoft treats `ThreadAbortedException' as a normal event as evident from this code: referencesource.microsoft.com/#System.Web/UI/Page.cs,4875 One thing that is against Response.End() is that it might fail aborting the response, which might result occasionally in the response being displayed.

.net - Is Response.End() considered harmful? - Stack Overflow

.net asp.net
Rectangle 27 9

A very simple solution that I figured out.

public ActionResult Edit(Person person)
{
    ModelState.Remove("Id"); // This will remove the key 

    if (ModelState.IsValid)
       {
           //Save Changes;
       }
    }
}

c# - ASP.NET MVC - Alternative for [Bind(Exclude = "Id")] - Stack Over...

c# asp.net-mvc-2 modelbinders
Rectangle 27 92

This question appears near the top of all google searches for information on response.end so for other searches like myself who wish to post CSV/XML/PDF etc in response to an event without rendering the entire ASPX page, this is how I do it. (overriding the render methods is overly complex for such a simple task IMO)

// Add headers for a csv file or whatever
Response.ContentType = "text/csv"
Response.AddHeader("Content-Disposition", "attachment;filename=report.csv")
Response.AddHeader("Pragma", "no-cache")
Response.AddHeader("Cache-Control", "no-cache")

// Write the data as binary from a unicode string
Dim buffer As Byte()
buffer = System.Text.Encoding.Unicode.GetBytes(csv)
Response.BinaryWrite(buffer)

// Sends the response buffer
Response.Flush()

// Prevents any other content from being sent to the browser
Response.SuppressContent = True

// Directs the thread to finish, bypassing additional processing
HttpContext.Current.ApplicationInstance.CompleteRequest()

You shouldn't be using an APSX page to do this. It's a lot of wasted effort. You are supposed to use an ASMX or Web Service, anything but an ASPX page.

@mattmanser - It's not always easy/best/advisable to have a separate page for different representation of the same resource. Think about REST, etc. If the client indicates they want csv, xml via a header or param, this method would certainly be the best, while still providing html support through asp.net's normal rendering facilities.

This didn't work for me. I had a page that worked with Response.End(), but using all kinds of combinations of Response.Close(), Response.Flush(). HttpContext.Current.ApplicationInstance.CompleteRequest() and various other things did not work if I had a GzipStream filter on the Response. What appeared to be happening was that the page was still being output along with my file. I finally overrode the Render() function (to be blank) and that solved it for me.

CompleteRequest skips parts of the application pipeline but will still run through the remainder of the page rendering process, its not an immediate stop like response.end, its more graceful. There are more in depth explanations as to why in other answers on this page.

.net - Is Response.End() considered harmful? - Stack Overflow

.net asp.net
Rectangle 27 92

This question appears near the top of all google searches for information on response.end so for other searches like myself who wish to post CSV/XML/PDF etc in response to an event without rendering the entire ASPX page, this is how I do it. (overriding the render methods is overly complex for such a simple task IMO)

// Add headers for a csv file or whatever
Response.ContentType = "text/csv"
Response.AddHeader("Content-Disposition", "attachment;filename=report.csv")
Response.AddHeader("Pragma", "no-cache")
Response.AddHeader("Cache-Control", "no-cache")

// Write the data as binary from a unicode string
Dim buffer As Byte()
buffer = System.Text.Encoding.Unicode.GetBytes(csv)
Response.BinaryWrite(buffer)

// Sends the response buffer
Response.Flush()

// Prevents any other content from being sent to the browser
Response.SuppressContent = True

// Directs the thread to finish, bypassing additional processing
HttpContext.Current.ApplicationInstance.CompleteRequest()

You shouldn't be using an APSX page to do this. It's a lot of wasted effort. You are supposed to use an ASMX or Web Service, anything but an ASPX page.

@mattmanser - It's not always easy/best/advisable to have a separate page for different representation of the same resource. Think about REST, etc. If the client indicates they want csv, xml via a header or param, this method would certainly be the best, while still providing html support through asp.net's normal rendering facilities.

This didn't work for me. I had a page that worked with Response.End(), but using all kinds of combinations of Response.Close(), Response.Flush(). HttpContext.Current.ApplicationInstance.CompleteRequest() and various other things did not work if I had a GzipStream filter on the Response. What appeared to be happening was that the page was still being output along with my file. I finally overrode the Render() function (to be blank) and that solved it for me.

CompleteRequest skips parts of the application pipeline but will still run through the remainder of the page rendering process, its not an immediate stop like response.end, its more graceful. There are more in depth explanations as to why in other answers on this page.

.net - Is Response.End() considered harmful? - Stack Overflow

.net asp.net
Rectangle 27 9

A very simple solution that I figured out.

public ActionResult Edit(Person person)
{
    ModelState.Remove("Id"); // This will remove the key 

    if (ModelState.IsValid)
       {
           //Save Changes;
       }
    }
}

c# - ASP.NET MVC - Alternative for [Bind(Exclude = "Id")] - Stack Over...

c# asp.net-mvc-2 modelbinders
Rectangle 27 93

The Java equivalent of PHP and "Classic" ASP would be JSP (JavaServer Pages) with scriptlets (embedded raw Java code). Scriptlets are considered poor practice in Java web development world. Taglibs and EL (Expression Language) should be preferred above scriptlets. The Java equivalent of ASP.NET (MVC) would be a Java MVC framework. There are a lot of Java-based MVC frameworks out, mostly providing a Servlet/Filter-based controller and taglibs to interact with the model (usually a Javabean) and the view (usually a JSP page, but XHTML is also possible).

To start, the Java EE API provides JSF (JavaServer Faces) for this, which in turn comes along with XHTML based templated view technology known as Facelets. Facelets is seen as a replacement of the good old JSP. Further, there are a lot of open source Java MVC frameworks which are built on top of the JSP/Servlet API and which are intended as an alternative/competition to JSF. You can find little information of all of them here, the popular ones being Spring MVC, Struts2 and Stripes.

@BalusC According to this question it seems that ASP.NET MVC is a request (action) MVC framework, is that correct? (I assume that request/action and component-based are the two unique/main groups of MVC frameworks). BTW I'm also curious about which would be some PHP equivalents to these.

web applications - What is the main-stream Java alternative to ASP.NET...

java web-applications frameworks
Rectangle 27 5

As an addition to the existing answers, C# 6 makes it possible to exclude the property in a safer way:

public ActionResult Edit(Person person)
{
    ModelState.Remove(nameof(Person.Id));

    if (ModelState.IsValid)
       {
           //Save Changes;
       }
    }
}
public ActionResult Index([Bind(Exclude = nameof(SomeDomainModel.Id))] SomeDomainModel model)

I like this answer, but I still believe you should use ViewModels and POCO's in regards to the Design Pattern and SoC.

c# - ASP.NET MVC - Alternative for [Bind(Exclude = "Id")] - Stack Over...

c# asp.net-mvc-2 modelbinders
Rectangle 27 3

You have a few options. You can disable ViewState, or you can use "plain AJAX".

If you choose to use "plain AJAX", you can write your low level JavaScript code or use libraries such as jQuery to make the AJAX calls easier.

On the server side, you'll need to expose some kind of endpoint for the AJAX calls to communicate to. Some people use WebMethod, but that has been deprecated and I would avoid this approach. You can use ASP.NET Web API in .NET 4.5, or in any version of .NET you can use handlers or generic handlers (.ashx) to expose endpoints.

@manson : thanx for the guidence , as i am new to programming could u please provide me some refrence where i could learn Web API.

ajax - Alternative to Updatepanel in ASP.net - Stack Overflow

asp.net ajax webforms updatepanel
Rectangle 27 5

Response.Clear();
Response.Statuscode = 404; //Your response here
Response.End;

I believe its important to clear the response first in case it is already partially populated

in .Net, you can use the HttpStatusCode enumeration to return the status code. Might make for easier readability if you're using esoteric status codes :) example: HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.Unauthorized;

Ah didn't realise that enumeration existed - I bet the source code is hundreds of lines long in defining it!

Corrections to apply so that it works in C# : correct StatusCode casing and Response.End() is a method.

Is it possible to manually send HTTP code 40x to client from ASP.NET W...

asp.net web-services http asmx
Rectangle 27 4

Any resources for implementing this in .NET MVC5?

entity framework - Alternative to Dynamic Data in Asp.Net Mvc - Stack ...

asp.net entity-framework breeze dynamic-data scaffolding
Rectangle 27 5

As an addition to the existing answers, C# 6 makes it possible to exclude the property in a safer way:

public ActionResult Edit(Person person)
{
    ModelState.Remove(nameof(Person.Id));

    if (ModelState.IsValid)
       {
           //Save Changes;
       }
    }
}
public ActionResult Index([Bind(Exclude = nameof(SomeDomainModel.Id))] SomeDomainModel model)

I like this answer, but I still believe you should use ViewModels and POCO's in regards to the Design Pattern and SoC.

c# - ASP.NET MVC - Alternative for [Bind(Exclude = "Id")] - Stack Over...

c# asp.net-mvc-2 modelbinders
Rectangle 27 2

There's a good article by Dave Ward on optimizing UpdatePanels. There are to major hints you should understand and use:

  • Page is reloaded completely even if only one UpdatePanel is actually changed. To optimize you can use Request["__EVENTTARGET"] == UpdatePanel1.ClientID hint described in article.
  • Use PreRender event to actually fill panels with data. Thus you'll avoid unnecessary data loading.

But if you have system that'll go under heavy load in future, it would be better to design it using web services but not update panels.

ajax - alternative for asp.net updatePanels - Stack Overflow

asp.net ajax updatepanel