[ASP.NET] Probleem met Replace Functie

Pagina: 1
Acties:

  • Denga
  • Registratie: September 2000
  • Laatst online: 10-04 15:02

Denga

The riding never stops....

Topicstarter
Ik heb een probleempje met de Replace Functie, en dat is het volgende, als ik één dingetje wil veranderen is het geen probleem zie:

code:
1
strResult = strResult.Replace("<", "!")


Dan vervangt ie dus alle < door ! (het is maar een voorbeeld !)

maar als ik doe:

code:
1
strResult = strResult.Replace("<span id=""MyLabel"">", " ")


Dan geeft ie een Runtime Error... Weet iemand waar dit aan kan liggen? }:O

Never eat yellow snow...


  • whoami
  • Registratie: December 2000
  • Laatst online: 21-04 17:18
quotes moet je escapen, ofwel moet je @ voor je string zetten.
(Als je c# gebruikt)

[ Voor 58% gewijzigd door whoami op 11-12-2005 16:55 ]

https://fgheysels.github.io/


  • NMe
  • Registratie: Februari 2004
  • Laatst online: 15-04 22:07

NMe

Quia Ego Sic Dico.

@whoami: zo te zien gebruikt hij VB, en dan escape je door je quotes te verdubbelen. :P

@Denga: krijg je die runtime error ook in een versimpelde case? Of alleen in je daadwerkelijke pagina? Maak eens een pagina die niets meer doet dan die replace en vervolgens het resultaat afdrukt. Volgens mij klopt je code namelijk wel, althans, voor zover ik een beetje van VB-varianten af weet. :P

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


  • whoami
  • Registratie: December 2000
  • Laatst online: 21-04 17:18
Welke runtime error krijg je precies ?

https://fgheysels.github.io/


Verwijderd

Waar plaats je deze code? Op welk moment van event afhandeling.

En is <span id="MyLabel"> code generereerd door ASP.NET? Zo ja, wat probeer je te bereiken? Wellicht dat ASP.NET de label niet meer kan vinden?

En laat de volledige run-time error eens zien...

  • Denga
  • Registratie: September 2000
  • Laatst online: 10-04 15:02

Denga

The riding never stops....

Topicstarter
Nou in de versimpelde versie doet ie het gewoon maar als ik 'm dus dubbel quote dan gaat het dus mis, ook als ik 'm enkel quote trouwens...

en de gehele code is:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<%

Dim Query As String = "http://www.url.nl"

Dim wc As New System.Net.WebClient()
Dim myDataBuffer As Byte() = wc.DownloadData(Query)

Dim strResult As String
strResult = Encoding.Default.GetString(myDataBuffer)

strResult = strResult.Replace("<span id=""MyLabel"">", " ")

myLabel.text = strResult

%>

<asp:Label id="MyLabel" runat="server"/>

[ Voor 14% gewijzigd door Denga op 11-12-2005 20:53 ]

Never eat yellow snow...


  • Denga
  • Registratie: September 2000
  • Laatst online: 10-04 15:02

Denga

The riding never stops....

Topicstarter
En de Runtime error kan ik je niet laten zien omdat ze bij de hoster de instellingen verkeerd hebben staan:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Server Error in '/' Application.
--------------------------------------------------------------------------------

Runtime Error 
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".


<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>
 

Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.


<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>



:(

Never eat yellow snow...


Verwijderd

Ten eerste kan je de span-tag niet op deze manier verwijderen.

Ten tweede heb je de replace functie niet nodig, als je een literal control gebruikt.

Ten derde ligt de fout niet aan de replace. En gebruikt de hoster geen verkeerde instellingen. Als je nou eens zelf een web.config bestand in dezelfde map neerzet en de instellingen zodanig veranderd dat je de foutmeldingen te zien krijgt, dan kom je al een stuk verder.
Als je foutmelding uiteindelijk te zien krijgt, dan weet je waar het aan ligt...


code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script runat="server">
Sub Page_Load
  Dim Query As String = "http://www.url.nl"

  Dim wc As New System.Net.WebClient()
  Dim myDataBuffer As Byte() = wc.DownloadData(Query)

  Dim strResult As String
  strResult = Encoding.Default.GetString(myDataBuffer)

  Literal1.text = strResult

End Sub
</script>
<asp:Literal id="Literal1" Text="" runat="server"/>

[ Voor 6% gewijzigd door Verwijderd op 11-12-2005 22:21 ]


  • Denga
  • Registratie: September 2000
  • Laatst online: 10-04 15:02

Denga

The riding never stops....

Topicstarter
Nou, na een paar daagjes rust ben ik er achter waar het probleem ligt...

Hij maakt problemen van de quotes die in het te vervangen stukje staat, en als ik die except geeft ie dezelfde foutmelding. En heb de except op diverse manieren geprobeerd:

code:
1
strResult.Replace("<span id=/"MyLabel/"><html>", "<html>")


code:
1
strResult.Replace("<span id=""MyLabel""><html>", "<html>")


en ik weet wel zeker dat het daar aan ligt want als ik de Replace functie vereenvoudig naar:

code:
1
strResult.Replace("<html>", "<html2>")


Dan is er geen probleem... Dus wat doe ik dan fout qua except? }:O

Never eat yellow snow...


  • MTWZZ
  • Registratie: Mei 2000
  • Laatst online: 13-08-2021

MTWZZ

One life, live it!

Je kunt in VB.Net niet escapen met \
Probeer dit eens op een kale pagina:
Visual Basic .NET:
1
2
3
4
Dim strBuff As String
strBuff = "<div>dit <span class=""foo"">is</span> een divje</div>"
strBuff = strBuff.Replace("<span class=""foo"">is</span>","")
Response.Write(strBuff)

Nu met Land Rover Series 3 en Defender 90


  • Not Pingu
  • Registratie: November 2001
  • Laatst online: 01-04 20:36

Not Pingu

Dumbass ex machina

Denga schreef op zondag 11 december 2005 @ 21:01:
En de Runtime error kan ik je niet laten zien omdat ze bij de hoster de instellingen verkeerd hebben staan:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Server Error in '/' Application.
--------------------------------------------------------------------------------

Runtime Error 
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".


<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>
 

Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.


<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>



:(
Zoals je al in die foutmelding ziet staan, moet je zelf een instelling doen die de fout laat zien. Dat is geen foute instelling van je hoster.
Dus lees wat er staat en maak een web.config file aan waarin je customErrors uitzet, dan krijg je de volledige foutmelding te zien.

Certified smart block developer op de agile darkchain stack. PM voor info.


  • pjonk
  • Registratie: November 2000
  • Laatst online: 29-12-2025
Zoals sinaasappelsap al adviseerde zou ik hier een literal control gaan gebruiken of zelf een control gaan aanmaken. Als je op deze manier HTML gaat genereren leidt dit al snel tot onleesbare spaghetti code met dubbele quotes rotzooi enzo.

C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
HtmlImage Image = new HtmlImage();
Image.Src = "http://plaatje.jpg";
Image.Width = 200;
Image.Height = 150;

// Render object to Html
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter tw = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
Image.RenderControl(hw);

// Output the generated HTML
Response.write sb.ToString()

Ja dit is meer typ werk, maar het is wel 10x leesbaarder.

[ Voor 5% gewijzigd door pjonk op 14-12-2005 11:16 ]

It’s nice to be important but it’s more important to be nice

Pagina: 1