Showing posts with label method. Show all posts
Showing posts with label method. Show all posts

Thursday, March 22, 2012

Server.Execute vs Server.Transfer

Hello,
I have read that you can workaround the common problem of the Thread.Abort exception by using the server.execute method instead of server.transfer when transfering to another page.

I started using server.transfer in order to make the URLReferrer property of the HTTP request show up properly when using smart navigation in the app. This worked fine, but I get the Thread.Abort execeptions now and then.

Will server.execute still allow the HTTP Request to contain a valid URLReferrer value like the server.transfer call did?

Thanks.From the docs (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpServerUtilityClassTransferTopic2.asp):

"Transfer calls End which raises a ThreadAbortException exception upon completion."

Server.GetLastError() in a Web Farm

If I am handling errors in my Global.Asax Application_Error method and this
resides on a web farm and I am trying to trap the last exception that was
thrown, I assume that Server.GetLastError() will only check for the last
error on the current server. What if I was redirected via load balancing to
a different server. How do I accomidate for this?If an exception occured, how would you get redirected to a different server?

Exception Occurs
local error handling
page error handling
global error handling

there's no redirection happening...it all happens in a single thread...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Daniel Williams" <Daniel Williams@.discussions.microsoft.com> wrote in
message news:79CDFA4C-0E4E-41D1-8F1E-AF3CF66DF570@.microsoft.com...
> If I am handling errors in my Global.Asax Application_Error method and
this
> resides on a web farm and I am trying to trap the last exception that was
> thrown, I assume that Server.GetLastError() will only check for the last
> error on the current server. What if I was redirected via load balancing
to
> a different server. How do I accomidate for this?

Server.GetLastError() in a Web Farm

If I am handling errors in my Global.Asax Application_Error method and this
resides on a web farm and I am trying to trap the last exception that was
thrown, I assume that Server.GetLastError() will only check for the last
error on the current server. What if I was redirected via load balancing to
a different server. How do I accomidate for this?If an exception occured, how would you get redirected to a different server?
Exception Occurs
local error handling
page error handling
global error handling
there's no redirection happening...it all happens in a single thread...
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
"Daniel Williams" <Daniel Williams@.discussions.microsoft.com> wrote in
message news:79CDFA4C-0E4E-41D1-8F1E-AF3CF66DF570@.microsoft.com...
> If I am handling errors in my Global.Asax Application_Error method and
this
> resides on a web farm and I am trying to trap the last exception that was
> thrown, I assume that Server.GetLastError() will only check for the last
> error on the current server. What if I was redirected via load balancing
to
> a different server. How do I accomidate for this?

Server.HTMLEncode

Hi,
The following is lifted straight from the MSDN help topic for
HttpServerUtility.HtmlEncode Method [C#]
---
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cTest+String%3e.".
[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();
---
However, when I run it, the value of EncodedString is "This is a <Test
String>." not "This+is+a+%3cTest+String%3e."
Am I missing something? Am I not using the correct encoding method?
Any assistance gratefully received.
Best,
Mark RaeHi,
Use Server.UrlEncode for the output you are expecting.
"Mark Rae" <mark@.mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:eBm3iJ$cEHA.592@.TK2MSFTNGP11.phx.gbl...
Hi,
The following is lifted straight from the MSDN help topic for
HttpServerUtility.HtmlEncode Method [C#]
---
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cTest+String%3e.".
[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();
---
However, when I run it, the value of EncodedString is "This is a <Test
String>." not "This+is+a+%3cTest+String%3e."
Am I missing something? Am I not using the correct encoding method?
Any assistance gratefully received.
Best,
Mark Rae
Mark Rae wrote:

> Hi,
> The following is lifted straight from the MSDN help topic for
> HttpServerUtility.HtmlEncode Method [C#]
> ---
> The following example encodes a string for transmission by HTTP. It encode
s
> the string named TestString, which contains the text "This is a <Test
> String>.", and copies it into the string named EncodedString as
> "This+is+a+%3cTest+String%3e.".
> [C#]
> String TestString = "This is a <Test String>.";
> StringWriter writer = new StringWriter();
> Server.HtmlEncode(TestString, writer);
> String EncodedString = writer.ToString();
> ---
> However, when I run it, the value of EncodedString is "This is a <Test
> String>." not "This+is+a+%3cTest+String%3e."
> Am I missing something? Am I not using the correct encoding method?
> Any assistance gratefully received.
> Best,
> Mark Rae
>
Try Server.UrlEncode instead. HtmlEncode is generating HTML, as it
would be expected to.
-Mike
"Mike Newton" <MNewton@.Addus.com> wrote in message
news:ewkETQ$cEHA.2236@.TK2MSFTNGP10.phx.gbl...
Mike & Silva,

> Try Server.UrlEncode instead. HtmlEncode is generating HTML, as it
> would be expected to.
Thanks very much. Is the MSDN topic wrong, then...?

Server.HTMLEncode

Hi,

The following is lifted straight from the MSDN help topic for
HttpServerUtility.HtmlEncode Method [C#]

-------------------
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cTest+String%3e.".

[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();
-------------------

However, when I run it, the value of EncodedString is "This is a <Test
String>." not "This+is+a+%3cTest+String%3e."

Am I missing something? Am I not using the correct encoding method?

Any assistance gratefully received.

Best,

Mark RaeHi,

Use Server.UrlEncode for the output you are expecting.

"Mark Rae" <mark@.mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:eBm3iJ$cEHA.592@.TK2MSFTNGP11.phx.gbl...
Hi,

The following is lifted straight from the MSDN help topic for
HttpServerUtility.HtmlEncode Method [C#]

-------------------
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cTest+String%3e.".

[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();
-------------------

However, when I run it, the value of EncodedString is "This is a <Test
String>." not "This+is+a+%3cTest+String%3e."

Am I missing something? Am I not using the correct encoding method?

Any assistance gratefully received.

Best,

Mark Rae
Mark Rae wrote:

> Hi,
> The following is lifted straight from the MSDN help topic for
> HttpServerUtility.HtmlEncode Method [C#]
> -------------------
> The following example encodes a string for transmission by HTTP. It encodes
> the string named TestString, which contains the text "This is a <Test
> String>.", and copies it into the string named EncodedString as
> "This+is+a+%3cTest+String%3e.".
> [C#]
> String TestString = "This is a <Test String>.";
> StringWriter writer = new StringWriter();
> Server.HtmlEncode(TestString, writer);
> String EncodedString = writer.ToString();
> -------------------
> However, when I run it, the value of EncodedString is "This is a <Test
> String>." not "This+is+a+%3cTest+String%3e."
> Am I missing something? Am I not using the correct encoding method?
> Any assistance gratefully received.
> Best,
> Mark Rae

Try Server.UrlEncode instead. HtmlEncode is generating HTML, as it
would be expected to.

-Mike
"Mike Newton" <MNewton@.Addus.com> wrote in message
news:ewkETQ$cEHA.2236@.TK2MSFTNGP10.phx.gbl...

Mike & Silva,

> Try Server.UrlEncode instead. HtmlEncode is generating HTML, as it
> would be expected to.

Thanks very much. Is the MSDN topic wrong, then...?

server.htmlencode method

hi to all,

As we know that the server.htmlencode method makes html encodeing so what i understand hat if i have a text like that <b>Test string</b>

then when i apply the server.htmlencode method on that text then the output will be :

<b>Test String</b>

and the output after applying this method will be displayed on a Web browser as:

<b>Test string</b>

so my question why we directly send the text <b>Test string</b> to the web browser without using the server.htmlencode method to make encoding?

so ineed some clarification on that topic.

your help is highly appreciated

Best regards

wissam1:

why we directly send the text <b>Test string</b> to the web browser without using the server.htmlencode method to make encoding?

If you do not encode, it will behave as markup (you would see a bolden string in your sample), with all security concerns eventually involved. If instead you do encode, it will render as a plain string.

That's all i guess.

HTH. -LV


HI

HtmlEncoding is done mostly to avoid XSS (Cross Site Scripting) attacks.
Google for more on that.!

Thanks

Tuesday, March 13, 2012

server.mappath

i want use a private collection of fonts. i want to tell the class file using the server.mappath method the location of the fonts folder.
but the class file throws an error when i used the server method there. is there any other ways to do it.

as of now i have avoided the problem by hardcoding it[by passing the physical location as a string]

But i would like to have another solution to my problem.

Try using HttpContext.Current.Server.MapPath

Thanks


That didn't work in the business logic. i added the system.web namespace and use the statement you gave me..but still it wont work

try

using

System.IO;

string

file =Path.Combine(Request.PhysicalApplicationPath,"/fonts/arial.ttf");

string fontlocation = HttpContext.Current.Server.MapPath("./Fonts") + fontName;

i used the above code,but it didnt' work


You cannot use . in the path.

string fontlocation = HttpContext.Current.Server.MapPath("/Fonts" + fontName);

Thanks


I just copied your code and tried to run the application, it threw my System.InvalidOperationException

My fonts folders resides in the application root folder. so how am i supposed to access it from the BLL[business logic layer]


Did you keep a breakpoint and check, where the exception was raised?

The above code is how you access the server.mappath in class file. (Make sure you are writing code in C# as the above code is in C#

Thanks


try

string fontsLocation = Request.ApplicationPath + "/Fonts";

Happy Coding


as i had said in my previous post, it threw, System.InvalidOperationException.

and yes i am writing them in C#.


Keep a breakpoint and check where it is throwing the xception.

Thanks


Yes it does, it did threw the exception i mentioned above sonow i have my coding in a try catch block.

can you post your complete code?

Thanks


PrivateFontCollection FontCollection =new PrivateFontCollection();try {string fontlocation =this.fontPath+"Fonts/"+this.FamilyName +".ttf";//string fontlocation = HttpContext.Current.Server.MapPath("./Fonts") + fontName; FontCollection.AddFontFile(fontlocation); FontFamily fontFamily = FontCollection.Families[0];this.imgFont =new Font(fontFamily,this.FontSize, style, GraphicsUnit.Pixel); }catch (System.IO.FileNotFoundException ex2) {this.familyName = System.Drawing.FontFamily.GenericSerif.Name;this.imgFont =new Font(this.FamilyName,this.FontSize, style, GraphicsUnit.Pixel); }