Categories
askquestion

What’s the best way to cache a user control or its associated data in asp.net mvc

What’s the best way to cache a user control or its associated data in asp.net mvc

Ask Question

Asked
11 years, 4 months ago

Active
7 years, 6 months ago

Viewed
316 times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

1

I am in the middle of implementing an application using ASP.NET MVC and would love to cache the data passed to user controls or the output rendering on some user controls that I render using the Html.RenderPartial, that way I don’t have to query the DB with every request I do to the controller for a new view.

asp.net-mvc caching outputcache html.renderpartial

share|improve this question

edited Jul 13 ’12 at 7:36

tereško

54.4k2121 gold badges8686 silver badges142142 bronze badges

asked Oct 9 ’08 at 11:26

samiqsamiq

2,49411 gold badge2424 silver badges2626 bronze badges

Giving that there is no solution as of yet for this question, I will leave the question unanswered and will updte once the MVC team comes up with a viable solution.

– samiq
Oct 18 ’08 at 12:59

add a comment
 | 

2 Answers
2

active

oldest

votes

3

That appears to be one of those 1 million dollar questions!

It seems that a lot of people are having that problem, but the solution is not trivial.

Check out an issue reported recently on the ASP.NET MVC Codeplex site…

share|improve this answer

answered Oct 13 ’08 at 2:27

Elijah ManorElijah Manor

17.3k1616 gold badges6767 silver badges7979 bronze badges

add a comment
 | 

0

I would maybe suggest using the sub controllers from the MVC Contrib and then caching the controller’s method using the OutputCache stuff.

share|improve this answer

answered Apr 25 ’09 at 3:14

rballrball

6,49355 gold badges4343 silver badges7171 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged asp.net-mvc caching outputcache html.renderpartial or ask your own question.

Blog

Podcast: Your Buddy is Typing

The 2020 Developer Survey is now open!

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

An account of my meeting with the Stack Overflow management team

Did Stack Exchange cut the number of negative comments nearly in half between…

Related

968How to force the browser to reload cached CSS/JS files?249How to cache data in a MVC application51How can I cache objects in ASP.NET MVC?478How to render an ASP.NET MVC view as a string?626What’s the difference between Cache-Control: max-age=0 and no-cache?640ASP.NET MVC – Set custom IIdentity or IPrincipal2738Flash CS4 refuses to let go0How to cache asp.net mvc user control190Prevent Caching in ASP.NET MVC for specific actions using an attribute1063Is Safari on iOS 6 caching $.ajax results?

Hot Network Questions

Windows 10 Search not loading, showing blank window

Need to withdraw an application unless their HR changes their rules – how to do so?

Why is it so difficult to collect Iowa caucus results as opposed to election results?

Best ways to learn all the illustrator tools and commands

Can a deterministic finite automaton ever go into an infinite loop?

Living next door to Alice

How wasteful is a voltage transformer?

Fifth year of my PhD and I hate my project. What should I do?

Why wouldn’t dragon-hide make me fire-resistant?

SQL Server – Select most recent record from each group when performance is critical

Why is 2019-nCoV prioritized over other infectious diseases?

Is the mortality rate of 2019-nCoV 41%?

How can I count the number of files in a directory and delete the oldest if the number exceeds 5

Zilog Z80 freezes while binary counting up to 65 536 (2^16)

Concentric rings on a snub square tiling

What is the verb for describing the movement of a cat’s paw when it is trying to hit something with it?

How to quickly and inexpensively deposit cash?

Debt management: 0% CC APR for 15 months vs 7% student loan debt

Why does my tea periodically alternate its rotational speed after stirring? (Link to video below)

Would this hit/miss houserule be balanced with bounded accuracy?

How does a Coronavirus “test kit” work?

Physical Motivation for Four-Velocity definition

Casting creatures as spells – searching for the rules

Do German professors in a Master’s program respond to students who email them interested in their research work?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

default

Categories
askquestion

How have you customised work items in Team System?

How have you customised work items in Team System?

Ask Question

Asked
11 years, 4 months ago

Active
3 years, 11 months ago

Viewed
205 times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

0

At my company we use the default agile process template with some modificiations. One modification we have made is added a field that indicates how to report time spent on a work item.

What customisations of the default process templates have you made? Have you customised a third party process template or maybe rolled your own from scratch?

I think it would be interesting to learn from others customisations of Team System’s process templates.

tfs tfs-workitem tfs-process-template

share|improve this question

edited Feb 18 ’16 at 17:05

community wiki

4 revs, 3 users 100%Magnus Lindhe

add a comment
 | 

1 Answer
1

active

oldest

votes

1

I’ve done a number of different modifications for several different clients. The majority of them are to add new “States” and “Transitions” to support the client’s change control, and SOX Compliance in once case. That particular client also wanted to enforce security on WHO could change the states in certain transitions – and who the Work Item could be assigned to.

I’ve also added a number of fields, common is an indicator of an “Emergency Change”, additional priority fields – and fields specific to the clients line-of-business.

If you use the “Template Editor” power tool – it is very easy. But follow normal best practices of any development. Have a development server seperate from your production TFS Server (or at very least – a test Team Project). Put your template(s) under version control (I like a seperate Team Project for “TFS Implementation” And make small changes incrementally.

share|improve this answer

answered Oct 24 ’08 at 23:31

fuzzbonefuzzbone

2,0221414 silver badges1414 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged tfs tfs-workitem tfs-process-template or ask your own question.

Blog

Podcast: Your Buddy is Typing

The 2020 Developer Survey is now open!

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

Did Stack Exchange cut the number of negative comments nearly in half between…

An account of my meeting with the Stack Overflow management team

Related

28Steps for changing process template for an existing project in TFS 20100TFS 2010 process template work item customisations109difference between Product Backlog Item and Feature in Team Foundation work item types1Using TFS as a Q/A tool0Is it possible to track and report working effort with Team Foundation Server?0TFS 2012 has additional work item type fields after export0What are the drawbacks (if any) in using Agile and CMMI process templates?1Adding a state to a Work Item workflow in TFS 20132Resetting the Work Item Type history in the TFS WorkItem Query-Designer

Hot Network Questions

Need help to explain “set a-rattling the sabers of”

Why does Agent Smith need to kill Neo and Morpheus in the Matrix?

What are the pros and cons of a credit card for a European?

Why does N(OH)3 not exist?

Debt management: 0% CC APR for 15 months vs 7% student loan debt

Half my power out, but firing up an appliance turns it back on

What are credit cards, debit cards, and other types of cards?

I accidentally unset $PATH. Why did `echo` still work?

Unlocked packages vs Unmanaged packages

Concentric rings on a snub square tiling

How does the Sleep spell work?

Fifth year of my PhD and I hate my project. What should I do?

Worst-case efficiency of PPP escaping mechanism

Why does the difference between 30 March and 1 March 2020 erroneously give 28 days instead of 29?

Calculate the Progressive Mean™

Need to withdraw an application unless their HR changes their rules – how to do so?

U.S. Army/Military’s response time to an army appearing in the middle of a major city

Intersection of circles – How can I reduce this golf code to 127 bytes?

What do the green, white and yellow bands mean on an airspeed indicator?

Easiest way to travel regularly from Essex to Cornwall

Windows 10 Search not loading, showing blank window

How to avoid comments about one line of code for cleanliness

Living next door to Alice

How to generate a random integer array satisfying complex constraints

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Categories
askquestion

Capturing console output from a .NET application (C#)

Capturing console output from a .NET application (C#)

Ask Question

Asked
11 years, 4 months ago

Active
1 month ago

Viewed
115k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

123

54

How do I invoke a console application from my .NET application and capture all the output generated in the console?

(Remember, I don’t want to save the information first in a file and then relist as I would love to receive it as live.)

c# .net debugging console

share|improve this question

edited Aug 12 ’11 at 13:05

Peter Mortensen

24.8k2020 gold badges8989 silver badges118118 bronze badges

asked Oct 9 ’08 at 11:27

GripsoftGripsoft

2,23077 gold badges2626 silver badges3030 bronze badges

Possible duplicate of Process.start: how to get the output?

– MiFreidgeim SO-stop being evil
Oct 28 ’16 at 0:26

Please see the dates on both questions and see which one is “duplicate”

– Gripsoft
May 30 ’17 at 16:46

“Possible duplicate” is a way to clean-up – to close similar questions and keep one with the best answers. The date is not essential. See Should I vote to close a duplicate question, even though it’s much newer, and has more up to date answers? If you agree that it requires clarification please vote on Add clarification link to “Possible duplicate” automated comment

– MiFreidgeim SO-stop being evil
May 31 ’17 at 0:12

add a comment
 | 

8 Answers
8

active

oldest

votes

158

This can be quite easily achieved using the ProcessStartInfo.RedirectStandardOutput property. A full sample is contained in the linked MSDN documentation; the only caveat is that you may have to redirect the standard error stream as well to see all output of your application.

Process compiler = new Process();
compiler.StartInfo.FileName = “csc.exe”;
compiler.StartInfo.Arguments = “/r:System.dll /out:sample.exe stdstr.cs”;
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();

Console.WriteLine(compiler.StandardOutput.ReadToEnd());

compiler.WaitForExit();

share|improve this answer

edited Aug 12 ’11 at 13:14

Peter Mortensen

24.8k2020 gold badges8989 silver badges118118 bronze badges

answered Oct 9 ’08 at 11:32

mdbmdb

46.6k99 gold badges6161 silver badges6262 bronze badges

3

If you don’t want the extra new line at the end, just use Console.Write instead.

– tm1
Aug 8 ’16 at 11:56

2

It should be noted that if you use ReadToEnd() in combination with a console application that has the capability to prompt the user for input. Eg: Overwrite File: Y or N? etc Then ReadToEnd can result in a memory leak, since the process never exits while waiting for user input. The safer way to capture output is to use the process.OutputDataReceived event handler and let the process notify your application of output to be received.

– Baaleos
May 4 ’18 at 13:45

add a comment
 | 

30

This is bit improvement over accepted answer from @mdb. Specifically, we also capture error output of the process. Additionally, we capture these outputs through events because ReadToEnd() doesn’t work if you want to capture both error and regular output. It took me while to make this work because it actually also requires BeginxxxReadLine() calls after Start().

using System.Diagnostics;

Process process = new Process();

void LaunchProcess()
{
process.EnableRaisingEvents = true;
process.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(process_OutputDataReceived);
process.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(process_ErrorDataReceived);
process.Exited += new System.EventHandler(process_Exited);

process.StartInfo.FileName = “some.exe”;
process.StartInfo.Arguments = “param1 param2”;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;

process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();

//below line is optional if we want a blocking call
//process.WaitForExit();
}

void process_Exited(object sender, EventArgs e)
{
Console.WriteLine(string.Format(“process exited with code {0}n”, process.ExitCode.ToString()));
}

void process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data + “n”);
}

void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data + “n”);
}

share|improve this answer

edited Sep 13 ’19 at 3:47

Sachin Joseph

12.8k33 gold badges3030 silver badges5252 bronze badges

answered Sep 21 ’16 at 18:37

Shital ShahShital Shah

34.4k77 gold badges150150 silver badges119119 bronze badges

3

Thank you, been looking for this for ages!

– C Bauer
Oct 11 ’16 at 13:09

1

Thank you. This is perfect.

– DrFloyd5
Aug 9 ’18 at 16:24

add a comment
 | 

13

Use ProcessInfo.RedirectStandardOutput to redirect the output when creating your console process.

Then you can use Process.StandardOutput to read the program output.

The second link has a sample code how to do it.

share|improve this answer

edited Oct 13 ’16 at 21:53

Uwe Keim

34.5k3434 gold badges148148 silver badges236236 bronze badges

answered Oct 9 ’08 at 11:32

Franci PenovFranci Penov

68.9k1414 gold badges120120 silver badges158158 bronze badges

add a comment
 | 

7

ConsoleAppLauncher is an open source library made specifically to answer that question. It captures all the output generated in the console and provides simple interface to start and close console application.

The ConsoleOutput event is fired every time when a new line is written by the console to standard/error output. The lines are queued and guaranteed to follow the output order.

Also available as NuGet package.

Sample call to get full console output:

// Run simplest shell command and return its output.
public static string GetWindowsVersion()
{
return ConsoleApp.Run(“cmd”, “/c ver”).Output.Trim();
}

Sample with live feedback:

// Run ping.exe asynchronously and return roundtrip times back to the caller in a callback
public static void PingUrl(string url, Action<string> replyHandler)
{
var regex = new Regex(“(time=|Average = )(?<time>.*?ms)”, RegexOptions.Compiled);
var app = new ConsoleApp(“ping”, url);
app.ConsoleOutput += (o, args) =>
{
var match = regex.Match(args.Line);
if (match.Success)
{
var roundtripTime = match.Groups[“time”].Value;
replyHandler(roundtripTime);
}
};
app.Run();
}

share|improve this answer

answered Mar 31 ’13 at 1:36

SlavaGuSlavaGu

75711 gold badge77 silver badges1414 bronze badges

add a comment
 | 

2

I’ve added a number of helper methods to the O2 Platform (Open Source project) which allow you easily script an interaction with another process via the console output and input (see http://code.google.com/p/o2platform/source/browse/trunk/O2_Scripts/APIs/Windows/CmdExe/CmdExeAPI.cs)

Also useful for you might be the API that allows the viewing of the console output of the current process (in an existing control or popup window). See this blog post for more details: http://o2platform.wordpress.com/2011/11/26/api_consoleout-cs-inprocess-capture-of-the-console-output/ (this blog also contains details of how to consume the console output of new processes)

share|improve this answer

answered Nov 26 ’11 at 18:02

Dinis CruzDinis Cruz

3,40722 gold badges2222 silver badges4646 bronze badges

Since then I’ve added more support for using the ConsoleOut (in this case if you start the .NET process your self). Take a look at: How to use the Console output in the C# REPL , Adding ‘Console Out’ to VisualStudio IDE as a native Window , Viewing ‘Console Out’ messages created inside UserControls

– Dinis Cruz
Dec 19 ’12 at 7:52

add a comment
 | 

1

From PythonTR – Python Programcıları Derneği, e-kitap, örnek:

Process p = new Process(); // Create new object
p.StartInfo.UseShellExecute = false; // Do not use shell
p.StartInfo.RedirectStandardOutput = true; // Redirect output
p.StartInfo.FileName = “c:\python26\python.exe”; // Path of our Python compiler
p.StartInfo.Arguments = “c:\python26\Hello_C_Python.py”; // Path of the .py to be executed

share|improve this answer

edited Apr 10 ’12 at 10:40

Dunya Degirmenci

40233 silver badges1717 bronze badges

answered May 17 ’10 at 16:18

livetogogolivetogogo

1911 bronze badge

add a comment
 | 

1

Added process.StartInfo.**CreateNoWindow** = true; and timeout.

private static void CaptureConsoleAppOutput(string exeName, string arguments, int timeoutMilliseconds, out int exitCode, out string output)
{
using (Process process = new Process())
{
process.StartInfo.FileName = exeName;
process.StartInfo.Arguments = arguments;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();

output = process.StandardOutput.ReadToEnd();

bool exited = process.WaitForExit(timeoutMilliseconds);
if (exited)
{
exitCode = process.ExitCode;
}
else
{
exitCode = -1;
}
}
}

share|improve this answer

edited Sep 9 ’15 at 19:34

jaunt

4,36944 gold badges2424 silver badges4949 bronze badges

answered Sep 9 ’15 at 19:30

Sergei ZinovyevSergei Zinovyev

93299 silver badges1313 bronze badges

When you use StandardOutput.ReadToEnd() it won’t return to next statement until end of app. so your timeout in WaitForExit(timeoutMilliseconds) does not work! (your code will hang!)

– S.Serpooshan
Jan 1 ’18 at 7:10

add a comment
 | 

0

I made a reactive version that accepts callbacks for stdOut and StdErr.
onStdOut and onStdErr are called asynchronously,
as soon as data arrives (before the process exits).

public static Int32 RunProcess(String path,
String args,
Action<String> onStdOut = null,
Action<String> onStdErr = null)
{
var readStdOut = onStdOut != null;
var readStdErr = onStdErr != null;

var process = new Process
{
StartInfo =
{
FileName = path,
Arguments = args,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = readStdOut,
RedirectStandardError = readStdErr,
}
};

process.Start();

if (readStdOut) Task.Run(() => ReadStream(process.StandardOutput, onStdOut));
if (readStdErr) Task.Run(() => ReadStream(process.StandardError, onStdErr));

process.WaitForExit();

return process.ExitCode;
}

private static void ReadStream(TextReader textReader, Action<String> callback)
{
while (true)
{
var line = textReader.ReadLine();
if (line == null)
break;

callback(line);
}
}

Example usage

The following will run executable with args and print

stdOut in white
stdErr in red

to the console.

RunProcess(
executable,
args,
s => { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(s); },
s => { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(s); }
);

share|improve this answer

answered Dec 17 ’19 at 11:46

3dGrabber3dGrabber

3,52211 gold badge2727 silver badges3535 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

draft saved
draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged c# .net debugging console or ask your own question.

Blog

Podcast: Your Buddy is Typing

The 2020 Developer Survey is now open!

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

An account of my meeting with the Stack Overflow management team

Did Stack Exchange cut the number of negative comments nearly in half between…

Linked

134

How to spawn a process and capture its STDOUT in .NET?

1

How to take the output of a BAT file and save it to a string

0

command prompt c#

0

Execute windows cmd prompt command through c# code.

292

Process.start: how to get the output?

20

Capture output of process synchronously (i.e. “when it happens”)

5

Read values already printed to the console

6

How to get the video duration using FFMPEG in C# asp.net

5

Is there a way to continuously mirror the result of Console.Write to a collection (array,list,etc)?

8

Capture coloured console output into WPF application

see more linked questions…

Related

104No output to console from a WPF application?568How can I save application settings in a Windows Forms application?921How can I get the application’s path in a .NET console application?1747Get int value from enum in C#775Reading settings from app.config or web.config in .NET852How do I force my .NET application to run as administrator?457How do I exit a WPF application programmatically?892How do I turn a C# object into a JSON string in .NET?687If a folder does not exist, create it1336Why not inherit from List<T>?

Hot Network Questions

Is the mortality rate of 2019-nCoV 41%?

How does a Coronavirus “test kit” work?

SQL Server – Select most recent record from each group when performance is critical

How does “It’s totally fucked” translate to Latin?

Why Didn’t the USSR Build An X-15?

Why is it so difficult to collect Iowa caucus results as opposed to election results?

How does the current remain the same in a circuit?

Can a deterministic finite automaton ever go into an infinite loop?

Zilog Z80 freezes while binary counting up to 65 536 (2^16)

How to show a “Yes” for a negative occurrence and “No” for a positive occurrence

My friend listed my name as a co-author on two journal papers without my permission

Print this maximally long URL

Some kind of measure

How to make set of equations appear side by side using empheq package?

Intersection of circles – How can I reduce this golf code to 127 bytes?

Need help to explain “set a-rattling the sabers of”

How would a Grey Goo robot compute given that it has no fixed form?

Can open-source software be peer-reviewed and published?

How many Imperial Inquisitors are there?

Acyclic group and finite CW-complex

Would this hit/miss houserule be balanced with bounded accuracy?

How does the math for the Iowa Democratic Caucuses work?

Why don’t they make an image of the black hole in the M33 galaxy?

My own Party are ruining the game for me. What should I do?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-cs

Categories
askquestion

SMTP with CRAM-MD5 in Java

SMTP with CRAM-MD5 in Java

Ask Question

Asked
11 years, 4 months ago

Active
7 years, 5 months ago

Viewed
6k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

6

3

I need to send email through an (external) SMTP server from Java however this server will only accept CRAM-MD5 authentication, which is not supported by JavaMail.

What would be a good way to get these emails to send? (It must be in Java.)

java smtp sasl

share|improve this question

edited Oct 9 ’08 at 11:41

Chris Jester-Young

194k4141 gold badges356356 silver badges406406 bronze badges

asked Oct 9 ’08 at 11:28

pvgoddijnpvgoddijn

10.4k1212 gold badges3939 silver badges5353 bronze badges

add a comment
 | 

7 Answers
7

active

oldest

votes

6

+100

Here is thread which says that you need to add the following property:

props.put(“mail.smtp.auth.mechanisms”, “CRAM-MD5”)

Also in Geronimo implementation there is CramMD5Authenticator

Hope it helps to resolve this old question.

share|improve this answer

edited Aug 24 ’12 at 14:13

answered Aug 24 ’12 at 14:04

Alexey OgarkovAlexey Ogarkov

2,8962020 silver badges2828 bronze badges

i accepted this answer because it seems like the solution. Havent tested it because our need to use this disappeared

– pvgoddijn
Aug 27 ’12 at 13:12

add a comment
 | 

5

Since Java Mail 1.4.4, CRAM-MD5 is supported for use with smtp.
Just set this parameter to your properties and it will work:

props.put(“mail.smtp.sasl.enable”, “true”);

share|improve this answer

answered Aug 28 ’12 at 9:03

PumucklinePumuckline

47855 silver badges1515 bronze badges

One day to late to get the bounty.

– Ralph
Aug 28 ’12 at 9:07

Setting mail.smtp.auth.mechanisms didn’t work for me, but this did (or possibly both are required).

– Chris Suter
Apr 19 ’13 at 3:56

add a comment
 | 

4

This doesn’t help you directly, however, IMAP connections in JavaMail do support SASL (and thus CRAM-MD5, see the Java SASL documentation) if you set the mail.imap.sasl.enable boolean property to true.

Unfortunately, there is no mail.smtp.sasl.enable property, and SASL cannot be enabled for SMTP in JavaMail. 🙁

However, you can download the JavaMail source code, and you can try to edit the SMTP code to support SASL in a similar manner to the IMAP code. Good luck!

share|improve this answer

edited Oct 9 ’08 at 12:03

answered Oct 9 ’08 at 11:52

Chris Jester-YoungChris Jester-Young

194k4141 gold badges356356 silver badges406406 bronze badges

3

The release notes of Java Mail 1.4.4 (oracle.com/technetwork/java/javamail/javamail144-1562675.html) indicate that there is now SASL Support for SMPT too.

– Ralph
Aug 20 ’12 at 8:50

add a comment
 | 

4

This probably won’t help you but CRAM-MD5 and CRAM-SHA1 are fairly easy to implement assuming you have the correct library (md5/sha1) and, idealy, a base64 encoding library (though the base64 stuff is fairly easy to implement yourself in a pinch).

The transaction looks like this:

C: AUTH CRAM-MD5
S: 334 BASE64(NONCE)
C: BASE64(USERNAME, ” “, MD5((SECRET XOR opad),MD5((SECRET XOR ipad), NONCE)))
S: 235 Authentication succeeded

Where NONCE is the once time challenge string, USERNAME is the username you are tryng to authenticate, SECRET is the shared secret (“password”), opad is 0x5C, and ipad is 0x36.

(CRAM-SHA1 would be the same transaction, but using SHA1() instead of MD5() to do the digesting)

So, here’s an example of a real CRAM-MD5 transaction

C: AUTH CRAM-MD5
S: 334 PDQ1MDMuMTIyMzU1Nzg2MkBtYWlsMDEuZXhhbXBsZS5jb20+
C: dXNlckBleGFtcGxlLmNvbSA4YjdjODA5YzQ0NTNjZTVhYTA5N2VhNWM4OTlmNGY4Nw==
S: 235 Authentication succeeded

Backing up the process a step you get:

S: 334 BASE64(“<[email protected]>”)
C: BASE64(“[email protected] 8b7c809c4453ce5aa097ea5c899f4f87”)

Backing up one step further to before the digest is calculated, you get:

S: 334 BASE64(“<[email protected]>”)
C: BASE64(“[email protected] “, MD5((“password” XOR opad),MD5((“password” XOR ipad), “<[email protected]>”)))

I guess that’s kind of confusing now that I write it out, but trust me, compared to trying to do NTLM/SPA by hand, it’s a breeze. If you’re motivated, it’s actually pretty easy to implement. Or maybe I’ve just spent way to long with my hands in the guts of mail clients and servers to think about it clearly anymore…

share|improve this answer

answered Oct 9 ’08 at 13:32

jj33jj33

6,54822 gold badges3232 silver badges4141 bronze badges

You don’t want to do that. Java has SASL support built in, and it’s much, much better to use Java’s built-in implementation than to hand-code one. The trick is to make JavaMail support SASL for SMTP, not CRAM-MD5 as such.

– Chris Jester-Young
Oct 10 ’08 at 4:34

“This probably won’t help you…” This question just made me remember all my own work struggling with AUTH protocols (which I implemented from hand because I was building a tool to verify third party tools). I agree that it’s generally a bad idea to reimplement if alternative is available.

– jj33
Oct 10 ’08 at 12:43

nods Fair enough, yes, I can imagine how much of a pain it would be to implement these by hand. Mwahahaha about SPA/NTLM, that’s one I’ve had to battle with too (thanks to people using clients that only do SPA and not CRAM-*).

– Chris Jester-Young
Oct 10 ’08 at 19:25

add a comment
 | 

4

Very Simple CRAMMD5 program in JAVA

import java.security.*;

class CRAMMD5Test
{
public static void main(String[] args) throws Exception
{
// This represents the BASE64 encoded timestamp sent by the POP server
String dataString = Base64Decoder.decode(“PDAwMDAuMDAwMDAwMDAwMEBteDEuc2VydmVyLmNvbT4=”);
byte[] data = dataString.getBytes();

// The password to access the account
byte[] key = new String(“password”).getBytes();

// The address of the e-mail account
String user = “[email protected]”;

MessageDigest md5 = MessageDigest.getInstance(“MD5″);
md5.reset();

if (key.length > 64)
key = md5.digest(key);

byte[] k_ipad = new byte[64];
byte[] k_opad = new byte[64];

System.arraycopy(key, 0, k_ipad, 0, key.length);
System.arraycopy(key, 0, k_opad, 0, key.length);

for (int i=0; i<64; i++)
{
k_ipad[i] ^= 0x36;
k_opad[i] ^= 0x5c;
}

byte[] i_temp = new byte[k_ipad.length + data.length];

System.arraycopy(k_ipad, 0, i_temp, 0, k_ipad.length);
System.arraycopy(data, 0, i_temp, k_ipad.length, data.length);

i_temp = md5.digest(i_temp);

byte[] o_temp = new byte[k_opad.length + i_temp.length];

System.arraycopy(k_opad, 0, o_temp, 0, k_opad.length);
System.arraycopy(i_temp, 0, o_temp, k_opad.length, i_temp.length);

byte[] result = md5.digest(o_temp);
StringBuffer hexString = new StringBuffer();

for (int i=0;i < result.length; i++) {
hexString.append(Integer.toHexString((result[i] >>> 4) & 0x0F));
hexString.append(Integer.toHexString(0x0F & result[i]));
}

System.out.println(Base64Encoder.encode(user + ” ” + hexString.toString()));
}
}

share|improve this answer

edited Feb 3 ’09 at 22:35

answered Dec 31 ’08 at 17:46

SkhaloSkhalo

add a comment
 | 

2

I tried the code on the example of a real CRAM-MD5 transaction, and also on the example given into the RFC 2195.

It does not work because the conversion to an hexadecimal string is not correct. For exmaple, with this code, you will obtain “b913a62c7eda7a495b4e6e7334d3890” instead of “b913a602c7eda7a495b4e6e7334d3890” and the sent authentication string will not be correct.

If you download the source code of javaMail, you will see the implementation of the function toHex into the unit “DigestMD5”. Using this conversion, it will work.

share|improve this answer

answered Jan 22 ’09 at 9:58

KiraKira

add a comment
 | 

1

Change:

for (int i=0; i<result.length; i++)
hexString.append(Integer.toHexString(0xFF & result[i]));

To:

for (int i=0;i < result.length; i++) {
hexString.append(Integer.toHexString((result[i] >>> 4) & 0x0F));
hexString.append(Integer.toHexString(0x0F & result[i]));
}

share|improve this answer

answered Feb 3 ’09 at 22:28

SkhaloSkhalo

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

draft saved
draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged java smtp sasl or ask your own question.

Blog

Podcast: Your Buddy is Typing

The 2020 Developer Survey is now open!

Featured on Meta

TLS 1.0 and TLS 1.1 deprecation for Stack Exchange services

Did Stack Exchange cut the number of negative comments nearly in half between…

An account of my meeting with the Stack Overflow management team

Linked

1

SMTP AUTH using CRAM-MD5

2

java PasswordAuthentication security

Related

6364Is Java “pass-by-reference” or “pass-by-value”?3192How do I efficiently iterate over each entry in a Java Map?1225How to round a number to n decimal places in Java1425Fastest way to determine if an integer’s square root is an integer3940How do I read / convert an InputStream into a String in Java?3037When to use LinkedList over ArrayList in Java?3422How do I generate random integers within a specific range in Java?386Send email using the GMail SMTP server from a PHP page2936How do I convert a String to an int in Java?3148How to create a memory leak in Java?

Hot Network Questions

Half my power out, but firing up an appliance turns it back on

Can a commercial airplane overtake another airplane going in the same direction?

How does Earth’s thermal radiation into space vary by location and time of day?

How wasteful is a voltage transformer?

Need to withdraw an application unless their HR changes their rules – how to do so?

Why did the Allies Invade French North Africa?

How to get a Real ID in California with my married name, when I am divorced?

What will happen if someone/a group can’t be confirmed that he/she/they commited a crime?

Why, in old movies and TV series, do they always use such extremely exaggerated wheel turns when driving a car?

Is it possible to maintain a gun functioning after thousands of years?

Are bread improvers really needed?

Why does my tea periodically alternate its rotational speed after stirring? (Link to video below)

How does a Coronavirus “test kit” work?

How do I explain the long life spans of Elves?

What are credit cards, debit cards, and other types of cards?

Dealing with unwanted “Joking” physical contact

How does “It’s totally fucked” translate to Latin?

How does the math for the Iowa Democratic Caucuses work?

How can I count the number of files in a directory and delete the oldest if the number exceeds 5

Why is it so difficult to collect Iowa caucus results as opposed to election results?

Calculate the Progressive Mean™

Why wouldn’t dragon-hide make me fire-resistant?

What are these types of logic diagrams called?

Why Didn’t the USSR Build An X-15?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-java

Categories
askquestion

How do ports work with IPv6?

How do ports work with IPv6?

Ask Question

Asked
11 years, 4 months ago

Active
1 year ago

Viewed
105k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

135

11

Conventional IPv4 dotted quad notation separates the address from the port with a colon, as in this example of a webserver on the loopback interface:

127.0.0.1:80

but with IPv6 notation the address itself can contain colons. For example, this is the short form of the loopback address:

::1

How are ports (or their functional equivalent) expressed in a textual representation of an IPv6 address/port endpoint?

tcp udp ipv6 ports

share|improve this question

edited Apr 14 ’15 at 3:32

Peter Wone

asked Oct 9 ’08 at 11:29

Peter WonePeter Wone

14.2k1111 gold badges6666 silver badges9797 bronze badges

add a comment
 | 

6 Answers
6

active

oldest

votes

183

They work almost the same as today. However, be sure you include [] around your IP.

For example : http://[1fff:0:a88:85a3::ac1f]:8001/index.html

Wikipedia has a pretty good article about IPv6: http://en.wikipedia.org/wiki/IPv6#Addressing

share|improve this answer

edited Aug 30 ’12 at 14:55

Mike Mackintosh

12.4k66 gold badges5050 silver badges7979 bronze badges

answered Oct 9 ’08 at 11:34

NicoNico

11.1k66 gold badges2929 silver badges3232 bronze badges

add a comment
 | 

31

The protocols used in IPv6 are the same as the protocols in IPv4. The only thing that changed between the two versions is the addressing scheme, DHCP [DHCPv6] and ICMP [ICMPv6]. So basically, anything TCP/UDP related, including the port range (0-65535) remains unchanged.

Edit: Port 0 is a reserved port in TCP but it does exist. See RFC793

share|improve this answer

edited Oct 9 ’08 at 11:50

answered Oct 9 ’08 at 11:33

Andrew MooreAndrew Moore

82.2k2929 gold badges155155 silver badges170170 bronze badges

add a comment
 | 

6

They’re the same, aren’t they? Now I’m losing confidence in myself but I really thought IPv6 was just an addressing change. TCP and UDP are still addressed as they are under IPv4.

share|improve this answer

edited Dec 18 ’08 at 17:19

Brian Knoblauch

16.9k1212 gold badges4848 silver badges7979 bronze badges

answered Oct 9 ’08 at 11:33

OliOli

200k5454 gold badges192192 silver badges270270 bronze badges

3

It is not just an address change. It is supposed to bring some cool features (for example global multicast). But yes, it is transparent to the upper layers.

– Tarnay Kálmán
Jan 18 ’09 at 5:34

4

It is “just” an address change. What you are talking about is addressing 🙂 But the reason it concerns/confuses people is that networking design treats “addressing” as addresses and “services” as port numbers. But you can’t do anything in TCP or UDP without both, so most people are trying to get the socket-level addressing to work, and can’t understand why people keep making up or changing the delimiter: spaces, then dots, then colons, then pound signs? So, yeah, I can see IPv6 making people worried.

– benc
Jul 26 ’09 at 20:18

add a comment
 | 

6

I’m pretty certain that ports only have a part in tcp and udp. So it’s exactly the same even if you use a new IP protocol

share|improve this answer

edited Dec 26 ’08 at 18:58

Brian Knoblauch

16.9k1212 gold badges4848 silver badges7979 bronze badges

answered Oct 9 ’08 at 11:33

svristsvrist

6,47977 gold badges3535 silver badges6161 bronze badges

1

DCCP and SCTP also have ports, but ports in SCTP are a little different because of the additional association identifier.

– james woodyatt
Nov 21 ’09 at 23:10

add a comment
 | 

6

Wikipedia points out that the syntax of an IPv6 address includes colons and has a short form preventing fixed-length parsing, and therefore you have to delimit the address portion with []. This completely avoids the odd parsing errors.

(Taken from an edit Peter Wone made to the original question.)

share|improve this answer

edited Jan 17 ’19 at 14:16

community wiki

4 revs, 3 users 71%Ajedi32

add a comment
 | 

5

I would say the best reference is Format for Literal IPv6 Addresses in URL’s where usage of [] is defined.

Also, if it is for programming and code, specifically Java, I would suggest this readsClass for Inet6Address java/net/URL definition where usage of Inet4 address in Inet6 connotation and other cases are presented in details. For my case, IPv4-mapped address Of the form::ffff:w.x.y.z, for IPv6 address is used to represent an IPv4 address also solved my problem. It allows the native program to use the same address data structure and also the same socket when communicating with both IPv4 and IPv6 nodes. This is the case on Amazon cloud Linux boxes default setup.

share|improve this answer

answered Mar 3 ’16 at 8:47

zhristzhrist

54544 silver badges1616 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

draft saved
draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged tcp udp ipv6 ports or ask your own question.

Blog

Podcast: Your Buddy is Typing

The 2020 Developer Survey is now open!

Featured on Meta

TLS 1.0 and TLS 1.1 deprecation for Stack Exchange services

Did Stack Exchange cut the number of negative comments nearly in half between…

An account of my meeting with the Stack Overflow management team

Linked

0

Setup Node.js Server to be accessed externally (external/public ip)

4

HHVM through Apache mod_fastcgi on debian

0

Can I use proxies ipv6 with CasperJS and SlimerJS?

Related

419Maximum length of the textual representation of an IPv6 address?1305Who is listening on a given TCP port on Mac OS X?12Definitive guide to understanding how to formulate an IPv6 address2Porting IPv4 Application to Dualstack IPv4/IPv60ipv6 equivalent for loopback address0Java binding to ::0 on IPv4-only machine?2Parse IPv6 addresses from /proc/net/tcp6 (python 2.7)2IPv6 loopback address http://0:0:0:0:0:0:0:1 – browser can’t connect. Method getRemoteHost()

Hot Network Questions

What do the green, white and yellow bands mean on an airspeed indicator?

Fifth year of my PhD and I hate my project. What should I do?

Casting creatures as spells – searching for the rules

Unlocked packages vs Unmanaged packages

How to get a Real ID in California with my married name, when I am divorced?

Intersection of circles – How can I reduce this golf code to 127 bytes?

It’s all about the sum of the digits

Employer asked me “What can we do to make your professional life better?”

What was so different about “Night of the Living Dead” from previous zombie movies?

Why would 2 aircraft fitted with the P&W PT6 Engine have different top speed?

How can I become guaranteed to move first in an encounter?

How to make set of equations appear side by side using empheq package?

Plains natives happen across a late 1890s airbase

Proving Non-Concreteness of a Category

How does a Coronavirus “test kit” work?

Are postdocs in your own institution frowned upon?

How wasteful is a voltage transformer?

Do German professors in a Master’s program respond to students who email them interested in their research work?

Physical Motivation for Four-Velocity definition

What made Jesus question at Mt 21:25 so effective or was it a bad question because the Jews could not answer?

Can a commercial airplane overtake another airplane going in the same direction?

94 Toyota Pickup hard to put into gear after clutch in too long

Fun with Flags part 1: something different

Circular diagram in LaTeX

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Categories
askquestion

Interesting UTF-8 Yahoo File Download Headers

Interesting UTF-8 Yahoo File Download Headers

Ask Question

Asked
11 years, 4 months ago

Active
10 years, 9 months ago

Viewed
1k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

2

My company runs a webmail service, and we were trying to diagnose a problem with Word downloads not opening automatically – the same *.doc file download from Yahoo Mail would open, but one from ours would not.

In the course of investigating the headers we saw this coming from Yahoo:

content-disposition attachment; filename*=”utf-8”word document.doc”;

Whereas our headers were like this:

content-disposition attachment; filename=”word document.doc”;

What exactly is Yahoo doing with the additional asterisk and utf-8” designation?

http-headers download

share|improve this question

edited May 1 ’09 at 8:41

bignose

21.2k1212 gold badges5959 silver badges9191 bronze badges

asked Oct 9 ’08 at 11:33

z7q2z7q2

4155 bronze badges

add a comment
 | 

2 Answers
2

active

oldest

votes

2

I think the correct answer to this is in rfc 2231:

Asterisks (“*”) are reused to provide the indicator that language and
character set information is present and encoding is being used. A
single quote (“‘”) is used to delimit the character set and language
information at the beginning of the parameter value. Percent signs
(“%”) are used as the encoding flag, which agrees with RFC 2047.

Specifically, an asterisk at the end of a parameter name acts as an
indicator that character set and language information may appear at
the beginning of the parameter value. A single quote is used to
separate the character set, language, and actual value information in
the parameter value string, and an percent sign is used to flag
octets encoded in hexadecimal. For example:

Content-Type: application/x-stuff;
title*=us-ascii’en-us’This%20is%20%2A%2A%2Afun%2A%2A%2A

share|improve this answer

answered Oct 9 ’08 at 13:50

z7q2z7q2

4155 bronze badges

add a comment
 | 

0

What Mime-Type are you using?

The asterisk is required as per RFC 2183 (http://www.ietf.org/rfc/rfc2183.txt):

In the extended BNF notation of [RFC 822], the Content-Disposition
header field is defined as follows:

disposition := “Content-Disposition” “:”
disposition-type
*(“;” disposition-parm)

disposition-type := “inline”https://stackoverflow.com/”attachment”
/ extension-token
; values are not case-sensitive

disposition-parm := filename-parm
/ creation-date-parm
/ modification-date-parm
/ read-date-parm
/ size-parm
/ parameter

filename-parm := “filename” “=” value

creation-date-parm := “creation-date” “=” quoted-date-time

modification-date-parm := “modification-date” “=” quoted-date-time

read-date-parm := “read-date” “=” quoted-date-time

size-parm := “size” “=” 1*DIGIT

quoted-date-time := quoted-string
; contents MUST be an RFC 822 `date-time’
; numeric timezones (+HHMM or -HHMM) MUST be used

share|improve this answer

answered Oct 9 ’08 at 11:47

AlphagerAlphager

1,25911 gold badge1010 silver badges1313 bronze badges

The asterisk is indicating repetition from 0 to infinity, not a literal character

– Greg
Oct 9 ’08 at 12:17

> What Mime-Type are you using? We were using the correct Mime-Type, application/msword. The original download problem was solved by providing a correct filesize (it was incorrect).

– z7q2
Oct 9 ’08 at 13:47

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

draft saved
draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged http-headers download or ask your own question.

Blog

Podcast: Your Buddy is Typing

The 2020 Developer Survey is now open!

Featured on Meta

TLS 1.0 and TLS 1.1 deprecation for Stack Exchange services

Did Stack Exchange cut the number of negative comments nearly in half between…

An account of my meeting with the Stack Overflow management team

Related

1249Proper MIME media type for PDF files1367How to send a header using a HTTP request through a curl call?1032Download a file with Android, and showing the progress in a ProgressDialog1075Custom HTTP headers : naming conventions550View HTTP headers in Google Chrome?666Are HTTP headers case-sensitive?505wget command to download a file and save as a different filename394Do I need Content-Type: application/octet-stream for file download?1What does this Content-Disposition header mean?0Spring REST file download unable to set header content-type attachment

Hot Network Questions

Why does Agent Smith need to kill Neo and Morpheus in the Matrix?

Why would 2 aircraft fitted with the P&W PT6 Engine have different top speed?

What are the pros and cons of a credit card for a European?

Proving Non-Concreteness of a Category

How can I become guaranteed to move first in an encounter?

Is it bad to use special characters in passwords?

Is the mortality rate of 2019-nCoV 41%?

selling appreciated stock vs gifting it to charity

Debt management: 0% CC APR for 15 months vs 7% student loan debt

What made Jesus question at Mt 21:25 so effective or was it a bad question because the Jews could not answer?

How to enable Flash Player plugin for Safari in MacOS Catalina?

Plains natives happen across a late 1890s airbase

I accidentally unset $PATH. Why did `echo` still work?

Do German professors in a Master’s program respond to students who email them interested in their research work?

Muscle spasms in legs during long distance running

Circular diagram in LaTeX

What will happen if someone/a group can’t be confirmed that he/she/they commited a crime?

94 Toyota Pickup hard to put into gear after clutch in too long

Why, in old movies and TV series, do they always use such extremely exaggerated wheel turns when driving a car?

How can I highlight how much better I’ve made our code and deal with a coworker that disagrees?

What are these types of logic diagrams called?

Why is 2019-nCoV prioritized over other infectious diseases?

How can I count the number of files in a directory and delete the oldest if the number exceeds 5

How would a Grey Goo robot compute given that it has no fixed form?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Categories
askquestion

How to prevent an exception in a background thread from terminating an application?

How to prevent an exception in a background thread from terminating an application?

Ask Question

Asked
11 years, 4 months ago

Active
2 years, 1 month ago

Viewed
27k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

42

18

I can hookup to AppDomain.CurrentDomain.UnhandledException to log exceptions from background threads, but how do I prevent them terminating the runtime?

c# .net exception

share|improve this question

edited Nov 29 ’13 at 11:49

Richard Ev

46.2k5252 gold badges172172 silver badges266266 bronze badges

asked Oct 9 ’08 at 11:36

luntainluntain

4,21066 gold badges3232 silver badges4646 bronze badges

add a comment
 | 

5 Answers
5

active

oldest

votes

39

First, you really should try not to have exceptions thrown – and not handled – in a background thread. If you control the way your delegate is run, encapsulate it in a try catch block and figure a way to pass the exception information back to your main thread (using EndInvoke if you explicitly called BeginInvoke, or by updating some shared state somewhere).

Ignoring a unhandled exception can be dangerous. If you have a real un-handlable exception (OutOfMemoryException comes into mind), there’s not much you can do anyway and your process is basically doomed.

Back to .Net 1.1, an unhandled exception in a backgroundthread would just be thrown to nowhere and the main thread would gladly plough on. And that could have nasty repercussions. So in .Net 2.0 this behavior has changed.

Now, an unhandled exception thrown in a thread which is not the main thread will terminate the process. You may be notified of this (by subscribing to the event on the AppDomain) but the process will die nonetheless.

Since this can be inconvenient (when you don’t know what will be run in the thread and you are not absolutely sure it’s properly guarded, and your main thread must be resilient), there’s a workaround. It’s intended as a legacy settings (meaning, it’s strongly suggested you make sure you don’t have stray threads) but you can force the former behavior this way :

Just add this setting to your service/application/whatever configuration file :

<configuration>
<runtime>
<!– the following setting prevents the host from closing when an unhandled exception is thrown –>
<legacyUnhandledExceptionPolicy enabled=”1″ />
</runtime>
</configuration>

It doesn’t seem to work with ASP.NET, though.

For more information (and a huge warning that this setting may not be supported in upcoming versions of the CLR) see http://msdn.microsoft.com/en-us/library/ms228965.aspx

share|improve this answer

edited Aug 16 ’17 at 12:48

Frederik Struck-Schøning

10.8k77 gold badges5050 silver badges5858 bronze badges

answered Oct 9 ’08 at 11:44

Yann SchwartzYann Schwartz

1

having try…catchs all over the place stinks. I woudl want just one in the unhandled location AND would not want my app to die as a simple nullpointer just kept happening when a user went to click “feature X” and we told them to use the other feature X button which was working…it didn’t shut the app down every time which annoys the user just as much as the original bug annoyed them.(booting an app takes time so it adds annoyance here to users)

– Dean Hiller
Dec 30 ’11 at 18:31

I am having problems with a buggy proprietary external library which erratically crashes the application with an (internal) ArgumentNullException. I would like to enable legacyUnhandledExceptionPolicy just for that library. Can this be done?

– chris
May 14 ’15 at 11:15

add a comment
 | 

9

From Joe Albahari’s excellent threading article:

The .NET framework provides a
lower-level event for global exception
handling:
AppDomain.UnhandledException. This
event fires when there’s an unhandled
exception in any thread, and in any
type of application (with or without a
user interface). However, while it
offers a good last-resort mechanism
for logging untrapped exceptions, it
provides no means of preventing the
application from shutting down – and
no means to suppress the .NET
unhandled exception dialog.

In production applications, explicit
exception handling is required on all
thread entry methods. One can cut the
work by using a wrapper or helper
class to perform the job, such as
BackgroundWorker (discussed in Part
3).

share|improve this answer

answered Oct 9 ’08 at 11:40

Mitch WheatMitch Wheat

268k3838 gold badges421421 silver badges509509 bronze badges

add a comment
 | 

3

Keeping the answer short, yes, you do can prevent the runtime from terminating.

Here is a demo of the workaround:

class Program
{
void Run()
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

Console.WriteLine(“Press enter to exit.”);

do
{
(new Thread(delegate()
{
throw new ArgumentException(“ha-ha”);
})).Start();

} while (Console.ReadLine().Trim().ToLowerInvariant() == “x”);

Console.WriteLine(“last good-bye”);
}

int r = 0;

void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Interlocked.Increment(ref r);
Console.WriteLine(“handled. {0}”, r);
Console.WriteLine(“Terminating ” + e.IsTerminating.ToString());

Thread.CurrentThread.IsBackground = true;
Thread.CurrentThread.Name = “Dead thread”;

while (true)
Thread.Sleep(TimeSpan.FromHours(1));
//Process.GetCurrentProcess().Kill();
}

static void Main(string[] args)
{
Console.WriteLine(“…”);
(new Program()).Run();
}
}

Essentially, you just did not let the runtime to show the “… program has stopped working” dialog.

In case you need to log the exception and silently exit, you can call Process.GetCurrentProcess().Kill();

share|improve this answer

answered Jun 29 ’09 at 4:38

bohdan_trotsenkobohdan_trotsenko

4,16522 gold badges3535 silver badges6262 bronze badges

1

ick. now my thread is hung and stuck forever and more and more threads get hung. I would rather have a way like java to keep on ploughing along…we had some exceptions that were not disastrous in java and the app kept on running and we told users to just avoid the corner case steps of 1,2,3. This seems bad that C# doesn’t support this well.

– Dean Hiller
Dec 30 ’11 at 18:29

1

Yes, this is a dirty trick, by the way. Threads are supposed to handle all the exceptions.

– bohdan_trotsenko
Jan 2 ’12 at 18:48

2

this is just sweeping the dirt under the rug, a very bad idea

– Weipeng L
Jul 18 ’18 at 2:55

add a comment
 | 

1

Here is a great blog post about this problem: Handling “Unhandled Exceptions” in .NET 2.0

IMO it would be right to handle exceptions in background threads manually and re-throw them via callback if necessary.

delegate void ExceptionCallback(Exception ex);

void MyExceptionCallback(Exception ex)
{
throw ex; // Handle/re-throw if necessary
}

void BackgroundThreadProc(Object obj)
{
try
{
throw new Exception();
}
catch (Exception ex)
{
this.BeginInvoke(new ExceptionCallback(MyExceptionCallback), ex);
}
}

private void Test()
{
ThreadPool.QueueUserWorkItem(new WaitCallback(BackgroundThreadProc));
}

share|improve this answer

answered Oct 9 ’08 at 11:51

akuaku

108k3030 gold badges163163 silver badges199199 bronze badges

add a comment
 | 

1

AppDomain.CurrentDomain.UnhandledException += (sender, e2) =>
{
Thread.CurrentThread.Join();
};

But be careful, this code will freeze all the stack memory of the Thread and thread’s managed object itself.
However, if your application is in determined state (may be you threw LimitedDemoFunctionalityException or OperationStopWithUserMessageException) and you are not developing 24/7 application this trick will work.

Finally, I think MS should allow developers to override the logic of unhandled exceptions from the top of the stack.

share|improve this answer

answered Dec 24 ’17 at 11:22

Eugene GorbovoyEugene Gorbovoy

57222 silver badges1616 bronze badges

1

Doing this is a terrible idea, but this answer didn’t deserve to be downvoted. Given that Microsoft doesn’t provide any ‘safe’ way of handling this, there’s nothing else you can do if the process-killing exception is being generated in third-part code that you can’t fix.

– Ashley
Oct 12 ’19 at 16:28

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

draft saved
draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged c# .net exception or ask your own question.

Blog

Podcast: Your Buddy is Typing

The 2020 Developer Survey is now open!

Featured on Meta

Planned Maintenance scheduled for Wednesday, February 5, 2020 for Data Explorer

Did Stack Exchange cut the number of negative comments nearly in half between…

An account of my meeting with the Stack Overflow management team

Visit chat

Linked

0

Alternative to deprecated Suspend method for threads?

11

Preventing Exceptions from 3rd party component from crashing the entire application

0

How to handle C# AppDomain.UnhandledException

1

Something swallowing up unhandled exceptions?

0

ASP.Net C# 4.0 – How to catch application thread exceptions

0

recover after exception, selenium tests, c sharp bindings

Related

1436Calling the base constructor in C#965How to escape braces (curly brackets) in a format string in .NET564Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on1949How do you assert that a certain exception is thrown in JUnit 4 tests?1356How do I update the GUI from another thread?1212Proper way to declare custom exceptions in modern Python?653How to print an exception in Python?2151Manually raising (throwing) an exception in Python688Understanding checked vs unchecked exceptions in Java1010How and when to use ‘async’ and ‘await’

Hot Network Questions

Why does N(OH)3 not exist?

How does a Coronavirus “test kit” work?

What is arbitrary code execution (ACE) and how does it affect speedrunning?

Does GDPR include UK customers, or not anymore?

Is it neccessary to clear browser cache periodically?

Why did 1-bit DRAM chips have separate data input and output?

Being asked to sign a “termination certificate” 6 months after resigning

Why does the difference between 30 March and 1 March 2020 erroneously give 28 days instead of 29?

U.S. Army/Military’s response time to an army appearing in the middle of a major city

Calculate the Progressive Mean™

Showing 3d spikes in QGIS?

How to handle large yet not big-data datasets?

Difference between :: and ::1

How wasteful is a voltage transformer?

Can open-source software be peer-reviewed and published?

My friend listed my name as a co-author on two journal papers without my permission

Unlocked packages vs Unmanaged packages

How can Picard have a Romulan housekeeper?

Half my power out, but firing up an appliance turns it back on

Concentric rings on a snub square tiling

How to write sign like that pic

Casting creatures as spells – searching for the rules

Best way to pass a 2d array to functions which size is unknown at compile time in pure C

Way to prove you are human when the Turing test is not sufficient

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-cs

Categories
askquestion

Splitting a semicolon-separated string to a dictionary, in Python

Splitting a semicolon-separated string to a dictionary, in Python

Ask Question

Asked
11 years, 4 months ago

Active
11 months ago

Viewed
83k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

81

28

I have a string that looks like this:

“Name1=Value1;Name2=Value2;Name3=Value3”

Is there a built-in class/function in Python that will take that string and construct a dictionary, as though I had done this:

dict = {
“Name1”: “Value1”,
“Name2”: “Value2”,
“Name3”: “Value3”
}

I have looked through the modules available but can’t seem to find anything that matches.

Thanks, I do know how to make the relevant code myself, but since such smallish solutions are usually mine-fields waiting to happen (ie. someone writes: Name1=’Value1=2′;) etc. then I usually prefer some pre-tested function.

I’ll do it myself then.

python string dictionary split

share|improve this question

edited Oct 9 ’08 at 11:48

Lasse V. Karlsen

asked Oct 9 ’08 at 11:38

Lasse V. KarlsenLasse V. Karlsen

324k8888 gold badges546546 silver badges742742 bronze badges

does your question require to support s = r’Name1=’Value=2′;Name2=Value2;Name3=Value3;Name4=”Va”lue;n3″‘ input (note: a semicolon inside a quoted string, a quote is escaped using a backslash, n escape is used, both single and double quotes are used)?

– jfs
Dec 21 ’14 at 20:42

This question of mine is over 6 years old, the code which involved this has long since been replaced 🙂 And no, it didn’t require support for quotes. I just wanted to have a prebuilt function instead of writing something myself. However, the code is long gone.

– Lasse V. Karlsen
Dec 21 ’14 at 20:43

add a comment
 | 

6 Answers
6

active

oldest

votes

137

There’s no builtin, but you can accomplish this fairly simply with a generator comprehension:

s= “Name1=Value1;Name2=Value2;Name3=Value3”
dict(item.split(“=”) for item in s.split(“;”))

[Edit] From your update you indicate you may need to handle quoting. This does complicate things, depending on what the exact format you are looking for is (what quote chars are accepted, what escape chars etc). You may want to look at the csv module to see if it can cover your format. Here’s an example: (Note that the API is a little clunky for this example, as CSV is designed to iterate through a sequence of records, hence the .next() calls I’m making to just look at the first line. Adjust to suit your needs):

>>> s = “Name1=’Value=2′;Name2=Value2;Name3=Value3″

>>> dict(csv.reader([item], delimiter=’=’, quotechar=”‘”).next()
for item in csv.reader([s], delimiter=’;’, quotechar=”‘”).next())

{‘Name2’: ‘Value2’, ‘Name3’: ‘Value3’, ‘Name1’: ‘Value1=2′}

Depending on the exact structure of your format, you may need to write your own simple parser however.

share|improve this answer

edited Oct 9 ’08 at 12:37

answered Oct 9 ’08 at 11:43

BrianBrian

97k2727 gold badges9898 silver badges105105 bronze badges

the code doesn’t handle quoting, try: s = “Name1=’Value;2’;Name2=Value2;Name3=Value3” (note: semicolon in the quoted Name1 value).

– jfs
Dec 21 ’14 at 20:18

1

I have no idea why the second example throws AttributeError: ‘_csv.reader’ object has no attribute ‘next’ for me. Of course I did import csv.

– Youngjae
Aug 8 ’19 at 11:10

add a comment
 | 

6

This comes close to doing what you wanted:

>>> import urlparse
>>> urlparse.parse_qs(“Name1=Value1;Name2=Value2;Name3=Value3”)
{‘Name2’: [‘Value2’], ‘Name3’: [‘Value3’], ‘Name1’: [‘Value1’]}

share|improve this answer

answered Mar 1 ’11 at 2:46

Kyle GibsonKyle Gibson

72277 silver badges1212 bronze badges

2

it breaks if there is & or % in the input.

– jfs
Dec 21 ’14 at 20:59

add a comment
 | 

3

s1 = “Name1=Value1;Name2=Value2;Name3=Value3”

dict(map(lambda x: x.split(‘=’), s1.split(‘;’)))

share|improve this answer

edited Mar 4 ’19 at 13:24

Petter Friberg

18.3k88 gold badges4444 silver badges8888 bronze badges

answered Mar 4 ’19 at 13:23

D. OmD. Om

3111 bronze badge

add a comment
 | 

0

It can be simply done by string join and list comprehension

‘,’.join([‘%s=%s’%x for x in d.items()])

>>d = {‘a’:1, ‘b’:2}
>>’,’.join([‘%s=%s’%x for x in d.items()])
>>’a=1,b=2’

share|improve this answer

answered Dec 23 ’14 at 11:37

vijayvijay

23833 silver badges99 bronze badges

add a comment
 | 

-1

IF your Value1, Value2 are just placeholders for actual values, you can also use the dict() function in combination with eval().

>>> s= “Name1=1;Name2=2;Name3=’string'”
>>> print eval(‘dict(‘+s.replace(‘;’,’,’)+’)’)
{‘Name2: 2, ‘Name3’: ‘string’, ‘Name1′: 1}

This is beacuse the dict() function understand the syntax dict(Name1=1, Name2=2,Name3=’string’). Spaces in the string (e.g. after each semicolon) are ignored. But note the string values do require quoting.

share|improve this answer

edited Apr 24 ’13 at 10:28

answered Apr 24 ’13 at 10:22

RabarberskiRabarberski

19.9k1717 gold badges6464 silver badges8383 bronze badges

Thanks, upvote string.replace worked well. Don’t know why I couldn’t split. I did i = textcontrol.GetValue() on tc box, then o = i.split(‘;’) but didn’t output a string just complained about format, unlike replace.

– Iancovici
Jun 13 ’13 at 18:18

1

s.replace(‘;’-based solution breaks if there is ; inside a quoted value. eval is evil and it is unnecessary in this case.

– jfs
Dec 21 ’14 at 21:05

add a comment
 | 

-2

easytiger $ cat test.out test.py | sed ‘s/^/ /’
p_easytiger_quoting:1.84563302994
{‘Name2’: ‘Value2’, ‘Name3’: ‘Value3’, ‘Name1’: ‘Value1’}
p_brian:2.30507516861
{‘Name2’: ‘Value2’, ‘Name3’: “‘Value3′”, ‘Name1’: ‘Value1’}
p_kyle:7.22536420822
{‘Name2’: [‘Value2’], ‘Name3’: [“‘Value3′”], ‘Name1’: [‘Value1’]}
import timeit
import urlparse

s = “Name1=Value1;Name2=Value2;Name3=’Value3′”

def p_easytiger_quoting(s):
d = {}
s = s.replace(“‘”, “”)
for x in s.split(‘;’):
k, v = x.split(‘=’)
d[k] = v
return d

def p_brian(s):
return dict(item.split(“=”) for item in s.split(“;”))

def p_kyle(s):
return urlparse.parse_qs(s)

print “p_easytiger_quoting:” + str(timeit.timeit(lambda: p_easytiger_quoting(s)))
print p_easytiger_quoting(s)

print “p_brian:” + str(timeit.timeit(lambda: p_brian(s)))
print p_brian(s)

print “p_kyle:” + str(timeit.timeit(lambda: p_kyle(s)))
print p_kyle(s)

share|improve this answer

edited Mar 27 ’13 at 0:28

answered Mar 26 ’13 at 23:59

easytigereasytiger

36433 silver badges1313 bronze badges

This doesn’t answer the question, because it doesn’t handle quoting. Try s = “Name1=’Value1=2′;Name2=Value2” and csv` (as in Brian’s accepted answer) or parse_qs (as in Kyle’s) will get it right, while yours will raise a ValueError. The OP specifically says “such smallish solutions are usually mine-fields waiting to happen”, which is why he wants a built-in or other well tested solution, and he gives an example that will break your code.

– abarnert
Mar 27 ’13 at 0:05

Ahh i didn’t see that. still. it would still be faster than all your solutions to preparse those in the main string before the iteration takes place and recalling the replace function thousands of times. I will update

– easytiger
Mar 27 ’13 at 0:13

I’m not sure how you’re going to preparse it. But even if you do, this seems like exactly what the OP was afraid of in a simple solution. Are you sure there are no other mines ahead? Can you prove it to the OP’s satisfaction?

– abarnert
Mar 27 ’13 at 0:18

OK, now that I’ve seen your edit… First, s.replace doesn’t do anything at all; it just returns a new string that you ignore. Second, even if you got it right (s = s.replace…), that doesn’t fix the problem, it just adds a new one on top of it. Try it on either my example or the OP’s.

– abarnert
Mar 27 ’13 at 0:21

The specification clearly includes handling the sample input he mentioned in his question, Name=’Value1=2′;. And your code doesn’t handle it. And I’m not sure how you’d sanitize that without parsing it in some way that will be just as slow as urlparse or csv in the first place.

– abarnert
Mar 27 ’13 at 0:24

 | 
show 5 more comments

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

draft saved
draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged python string dictionary split or ask your own question.

Blog

Podcast: Your Buddy is Typing

The 2020 Developer Survey is now open!

Featured on Meta

Planned Maintenance scheduled for Wednesday, February 5, 2020 for Data Explorer

Did Stack Exchange cut the number of negative comments nearly in half between…

An account of my meeting with the Stack Overflow management team

Linked

1

How to convert a string into dictionary in python 3

-4

Python String to dict while separator is ‘=’

0

Make a string into dictionary

101

Evaluating a mathematical expression in a string

7

How to split comma-separated key-value pairs with quoted commas

4

String to Dictionary Python

1

Passing dictionary elements as arguments to a function

1

Parse string with three-level delimitation into dictionary

0

Parsing message field of Windows Event Logs (security) with pandas

1

Can I avoid such cumbersome list comprehension

see more linked questions…

Related

6343What is the difference between String and string in C#?4506How do I merge two dictionaries in a single expression?5525What are metaclasses in Python?2929How do I iterate over the words of a string?3423How do I sort a dictionary by value?2487Add new keys to a dictionary?2683Check if a given key already exists in a dictionary7429How to check whether a string contains a substring in JavaScript?2971Iterating over dictionaries using ‘for’ loops3601Does Python have a string ‘contains’ substring method?

Hot Network Questions

Why wouldn’t dragon-hide make me fire-resistant?

Why “abilities” of Dryad of the Ilysian Grove aren’t considered as abilities?

Would this hit/miss houserule be balanced with bounded accuracy?

How to make set of equations appear side by side using empheq package?

How can I count the number of files in a directory and delete the oldest if the number exceeds 5

How to avoid comments about one line of code for cleanliness

Could a fan be used to prevent overheating on a Venus bound space probe?

Can a commercial airplane overtake another airplane going in the same direction?

Do German professors in a Master’s program respond to students who email them interested in their research work?

Medical provider is threatening to send me to collections over a debt I do not owe

94 Toyota Pickup hard to put into gear after clutch in too long

How can I highlight how much better I’ve made our code and deal with a coworker that disagrees?

What is the opinion of people outside the United States on the impeachment?

Does higher impedance speakers generate clearer voice?

How does the math for the Iowa Democratic Caucuses work?

What are the pros and cons of a credit card for a European?

Is it bad to use special characters in passwords?

Why is 2019-nCoV prioritized over other infectious diseases?

Does a Glyph of Warding have its own agency or a limited omniscience in the game?

My own Party are ruining the game for me. What should I do?

Some kind of measure

How does the current remain the same in a circuit?

What will happen if someone/a group can’t be confirmed that he/she/they commited a crime?

Why does my tea periodically alternate its rotational speed after stirring? (Link to video below)

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-py

Categories
askquestion

The most flexible framework architecture for web development? [closed]

The most flexible framework architecture for web development? [closed]

Ask Question

Asked
11 years, 4 months ago

Active
11 years, 4 months ago

Viewed
2k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

4

5

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 6 months ago.

Obviously, there is no one single solution that would satisfy everyone’s needs; an architecture is always a trade-off. I want to create a framework, originally aimed at RAD of web games. Target language is PHP, although the architecture should be widely applicable.

Goals that I have in head for this framework are: flexibility in ways you can achieve the result; maximal comfort for developers; connecting modules like LEGO® blocks; many types of input, many types of output, one format for processing.

The goals that are not a priority are speed, enterprise use and making money. It’s supposed to be an open source project.

The cornerstone of this design is that all content, before transformation, is processed in XML (idea based on EAI system I’ve worked with, eGate). The data abstraction layer – hopefully some smart ORM – is not important now. The output will be generated using XSLT or any other custom modules, for virtually any client – HTML for old browsers, XHTML/HTML5 for modern browsers, simple HTML for mobile clients, XML for AJAX/XMLRPC, etc.

Main reasons for using XML are:

it’s a well-known standard
existing tools like XPath, SimpleXML and DOM for navigating and modifying the content
XSLT providing a powerful and unified way to transform the code into any tag soup
I find the XML markup very easily readable, therefore I don’t think that advantages of JSON or YAML make a difference here
The content can be stacked easily, and it the order of the content doesn’t really matter as long as it’s transformed correctly with XSLT

The page generation process would consist of these phases:

Pre-processing: initializing modules, processing GPCS data, applying default [XML] templates
Processing/generation: main part of business logic, generating the bloated XML with maximum data (although hopefully optimized not to generate balast)
Processing: some additional business logic, e.g. cutting down some of the markup, preparing for transformation, reporting, statistics, etc.
Post-processing: parsing XML through the transformation engine (most probably just XSLT), output.

The content would be generated with a lot of meta-data (e.g. tags, permissions, importance, necessity, aimed output type), which would be stripped down during post-processing.

So, my question is: except for speed, what is the downfall of this solution? Where it could go wrong both during the development/maintenance of the framework, and its applications? What are the downsides of this architecture?

php architecture frameworks

share|improve this question

asked Oct 9 ’08 at 11:40

analytikanalytik

71255 silver badges1515 bronze badges

add a comment
 | 

5 Answers
5

active

oldest

votes

3

XSLT can be bulky to manage, and essentially adds an extra programming language that developers would have to work in (at least if I understand your description correctly). My experience has been that relatively few people know it, and even fewer can make it do what they want.

share|improve this answer

answered Oct 9 ’08 at 19:18

acrosmanacrosman

11.8k1010 gold badges3333 silver badges5151 bronze badges

My experience with XSLT has shown none of these drawbacks.

– dacracot
Oct 9 ’08 at 21:17

You raise a valid point about amount of people mastering XSLT; there is some dichotomy in coupling PHP with XSLT, but it seems to be the only formal language for transforming XML. I’ll probably want to offer an alternative to XSLT. Thanks.

– analytik
Oct 10 ’08 at 1:19

add a comment
 | 

2

I’m not sure what “flexible framework” to suggest to you either. It all kinda depends on what you’re comfortable with and your personal taste.

One thing I do know is that, how appealing it may look at first, is to stay away from XSLT. Doing Hello World type stuff and simple examples with XSLT is pretty straight forward. However, more complex projects become completely unmanageable (not to mention unreadable) with XSLT. My experience is that it puts a massive strain on the project.

share|improve this answer

answered Oct 9 ’08 at 21:08

LukeLuke

18k2929 gold badges9393 silver badges159159 bronze badges

1

My experience with XSLT has shown none of these drawbacks.

– dacracot
Oct 9 ’08 at 21:35

add a comment
 | 

1

I think you are looking at a highly complicated solution. It is a major effort to simply design and build out the Schema’s that you will be using. If your on a project that involves more than 5-6 people total you likely need to have an organized schema design effort. I think this is a point you are aware of.

I question and possibly take issue of the selection of PHP on the front end. I also think you are deciding on XML in a large sense mistakenly.

Here is what I do:

Build a service layer using Grails.org
Keep every resource that can be RESTFUL in rest
Use the X-fire plugin in Grails to build out any SOAP services that need to be built
Take advantage of GORM and RAD functionality of Grails to reduce development time.
Construct clients in X or Y language or platform to consume these services.

I definetly would want the speed of pure Java doing all of my XML translation/processing. If you have large documents then it will take considerable time processing these.

You understand the forces of your environment better than anyone, but I would caution you to do the simplest thing that works first and not over-architect.

share|improve this answer

answered Oct 9 ’08 at 19:28

Daniel HonigDaniel Honig

3,79855 gold badges2121 silver badges2424 bronze badges

Thanks for the opinion. However, even when my idea is overly complex for a simple CMS, it won’t involve lengthy document processing – I’m quite sure that processing my XML with XSLT in PHP will be much faster and a lot less complicated than calling a webservice that was built using YET another lang.

– analytik
Oct 10 ’08 at 1:23

add a comment
 | 

1

What you describe could likely be implemented using tox. It uses a hybrid MVC-ARS architecture. The obstacle that I see is the cost point tox presents because of its dependency on Oracle. Of course, since it is open source, you could convert it to Postgresql.

share|improve this answer

edited May 23 ’17 at 10:32

Community♦

111 silver badge

answered Oct 9 ’08 at 21:24

dacracotdacracot

19.2k2424 gold badges9494 silver badges147147 bronze badges

let me know if you have any questions about tox, the question button of the web site come to me

– dacracot
Oct 10 ’08 at 4:17

add a comment
 | 

-2

I’ve worked on a few web games in the past and, to be honest, none of them have ever needed anything this complex and unwieldy.

share|improve this answer

answered Oct 9 ’08 at 12:55

Robert RouseRobert Rouse

4,35311 gold badge1616 silver badges1919 bronze badges

add a comment
 | 

Not the answer you’re looking for? Browse other questions tagged php architecture frameworks or ask your own question.

Blog

Podcast: Your Buddy is Typing

The 2020 Developer Survey is now open!

Featured on Meta

TLS 1.0 and TLS 1.1 deprecation for Stack Exchange services

An account of my meeting with the Stack Overflow management team

In case you missed it: Shog9 and Robert Cartaino are no longer staff members…

Linked

0

What is the equivalent of Oracle’s REF CURSOR in Postgresql when using JDBC?

3

Is MVC-ARS preferable to classic MVC to prevent overloading?

Related

853What is the difference between a framework and a library?342Software Design vs. Software Architecture321Recommendations of Python REST (web services) framework?616What exactly is Spring Framework for?195What Scala web-frameworks are available?150How To Create a Flexible Plug-In Architecture?1430How to “add existing frameworks” in Xcode 4?0Can give me some advice about Web application architecture0PHP MVC for XML/ XSL0KooBoo & Servicestack Architecture / Design questions

Hot Network Questions

selling appreciated stock vs gifting it to charity

My own Party are ruining the game for me. What should I do?

Can a deterministic finite automaton ever go into an infinite loop?

What happens to the target of a “permanent” True Polymorph spell, when its caster dies

Should I cite an article that I can’t find?

Will transferring over PPP data stream containing only reserved bytes 0x7E, 0xFF, 0x03 reduce bandwidth by 50% because of escaping?

Why does the difference between 30 March and 1 March 2020 erroneously give 28 days instead of 29?

Debt management: 0% CC APR for 15 months vs 7% student loan debt

SQL Server – Select most recent record from each group when performance is critical

If the Concorde had an engine fail at cruise altitude, would they enter the coffin corner?

My friend listed my name as a co-author on two journal papers without my permission

Employer asked me “What can we do to make your professional life better?”

feminine form of λύκος

Are postdocs in your own institution frowned upon?

What’s the etiquette for giving checkmate on board?

I accidentally unset $PATH. Why did `echo` still work?

Zilog Z80 freezes while binary counting up to 65 536 (2^16)

Crossed & nested random effects model

How can I highlight how much better I’ve made our code and deal with a coworker that disagrees?

I was playing a tournament and some kids were talking about the game in a foreign language

Question about Iowa Caucus math

Half my power out, but firing up an appliance turns it back on

How can I count the number of files in a directory and delete the oldest if the number exceeds 5

Need to withdraw an application unless their HR changes their rules – how to do so?

more hot questions

lang-php

Categories
askquestion

How to force a reboot instead of shutdown (XP)

How to force a reboot instead of shutdown (XP)

Ask Question

Asked
11 years, 4 months ago

Active
10 years, 11 months ago

Viewed
25k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

3

I have a Windows XP SP2 virtual machine which can be accessed via VNC. It’s also running Deep Freeze so there should be no problem in forcing it to reboot. I am looking for a way to force the operating system to reboot instead of shutting down or completely remove the ability to shut down the machine using software applications (such as the usual way from the start menu, the shutdown program or other custom programs).

Thank you,
Tom

windows shutdown restart reboot

share|improve this question

asked Sep 16 ’08 at 16:17

TomTom

add a comment
 | 

4 Answers
4

active

oldest

votes

2

To remove the ability to shut down then your best bet is to create a group policy for the user/user group and specify that they can only restart the system. I have done this in the past to ensure that only the administrator account can shut down a computer. it has prevented me from mistakenly shutting down a remote pc at 2am in the morning when i meant to re-start it.

share|improve this answer

answered Sep 16 ’08 at 16:23

Toby MillsToby Mills

97622 gold badges99 silver badges1313 bronze badges

add a comment
 | 

5

Try this:

shutdown -r -t 1 -f

Alex

share|improve this answer

answered Sep 16 ’08 at 16:18

Alex FortAlex Fort

16.3k55 gold badges3838 silver badges5151 bronze badges

add a comment
 | 

0

In XP there is a DOS command called shutdown. If you type shutdown /? from a command prompt you will see the options available. Using this you can create a Batch file.

share|improve this answer

answered Sep 16 ’08 at 16:19

Toby MillsToby Mills

97622 gold badges99 silver badges1313 bronze badges

add a comment
 | 

0

Try DShutdown.exe. It’s flexible and can do all these things.

share|improve this answer

answered Sep 16 ’08 at 16:19

BurkhardBurkhard

13.6k2121 gold badges8080 silver badges102102 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

draft saved
draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Blog

Podcast: Your Buddy is Typing

The 2020 Developer Survey is now open!

Featured on Meta

Planned Maintenance scheduled for Wednesday, February 5, 2020 for Data Explorer

In case you missed it: Shog9 and Robert Cartaino are no longer staff members…

An account of my meeting with the Stack Overflow management team

Related

2117How can you find out which process is listening on a port on Windows?653How do I shutdown, restart, or log off Windows via a bat file?8How to force restart a Windows box using VBScript?3Qt Application Blocking System Shutdown1Replace shutdown with hibernate2504How to install pip on Windows?1Force shutdown in MSI installer?0How do I execute commands before shutdown in Windows 7 (and before it kills all running programs?)

Hot Network Questions

What is a ground fault?

What title did Qing China use for US presidents?

From Hiroshima to Fukuoka via local trains

When can I hyphenate “in-place”?

Difference between :: and ::1

Why would 2 aircraft fitted with the P&W PT6 Engine have different top speed?

Could a fan be used to prevent overheating on a Venus bound space probe?

Why are the numbers on a ball in a lotto draw categorical nominal instead of categorical ordinal?

Debt management: 0% CC APR for 15 months vs 7% student loan debt

C++ Calculator for complex numbers – follow-up

Is it neccessary to clear browser cache periodically?

Do German professors in a Master’s program respond to students who email them interested in their research work?

Way to prove you are human when the Turing test is not sufficient

Employer asked me “What can we do to make your professional life better?”

How can I count the number of files in a directory and delete the oldest if the number exceeds 5

Why don’t they make an image of the black hole in the M33 galaxy?

Is the Senate Compelled to Acquit Trump?

Why does my tea periodically alternate its rotational speed after stirring? (Link to video below)

Does ancient Greek have its own terms for grammar?

Why do Counter-Strike players switch weapons so frequently?

Can a commercial airplane overtake another airplane going in the same direction?

Does Kakao debit card work in the US and Canada?

What would be the best melee weapon(s) to emphasize arboreal mobility?

Constructing an object: should I expose or hide parameters passed to the constructor?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.